The content of the string within the .ts file sourced from an external JSON document

I'm feeling a bit disoriented about this topic. Is it feasible to insert a string from an external JSON file into the .ts file? I aim to display the URLs of each item in an IONIC InAppBrowser. For this reason, I intend to generate a variable with a specific item so that I can integrate it into the InAppBrowser.

Thank you for your assistance.

Items.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

// Importing service
import { ItemsProvider } from '../../providers/items/items';
// Importing URL from config
import { URL_SERVICES } from './../../config/url.services';

@Component({
  selector: 'page-items-eur',
  templateUrl: 'items-eur.html',
})
export class ItemsEurPage {

  country = {};

  images = URL_SERVICES + "/imgs";
  itemsData:any [] = [];
  sliderValue: number = 0;
  selection: string = "";
  itemAssociation: string = "";

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public _creP: ItemsProvider,
  ) {
    console.log( navParams );
    this.country = this.navParams.get("country");

    if (this.country == "Spain") {
      this._creP.load_items_esp()
        .subscribe(
          (response)=>{
          console.log(response);
          this.itemsData = response["results"];
      } )
    }

    this.itemAssociation = this.itemsData[0],["acf"],["link"]; // The desired string to display for each item

    console.log(this.itemAssociation);

  }
}

JSON FILE

{
    "results": [{
            "acf": {
                "name": "Item1",
                "link": "https://www.google.com"
            }
        },
         "acf": {
                "name": "Item2",
                "link": "https://www.facebook.com"
          
            }
        }
    ]
}

UPDATE - Load JSON file of ItemsProvider

  load_items_esp(){
    return this.http.get("https://my_server.com/items_esp.json");
  }

Answer №1

To iterate through your JSON data and display all items in a single line, you can use the following code snippet. Here is the reference to the stackblitz demo: https://stackblitz.com/edit/js-r3lvpq

var jsonData = {
    "results": [
        {
            "details": {
                "title": "Item1",
                "link": "https://www.google.com"
            }
        },
        {
            "details": {
                "title": "Item2",
                "link": "https://www.facebook.com"
            }
        }
    ]
};

jsonData.results.forEach(
  (result) => {
    console.log('Title: ' + result.details.title + ' Link: ' + result.details.link);
  }
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Socket connection issue causing Laravel Event not to display on registration

I want to display notifications for new users who have registered on my website, so that existing logged-in users can see messages like "blabla has registered...". To achieve this, I first created an Event class along with a channel setup: class UserSign ...

What is the process for launching my Angular 8 application on an Apache server running Ubuntu 18?

I am looking for a way to showcase my compiled "dist" folder, which was generated on a Windows system using the command "ng build --prod", on an Ubuntu 18 server that is running Apache. Any suggestions on how I can achieve this? ...

Error with Firebase authentication on a Next.js project using TypeScript

I recently started a personal project using Next.js, Typescript, and Firebase for authentication and database management. While working on a sign-in page with Google integration, I encountered an error labeled as auth/argument-error. According to the Fireb ...

What is the best way to update JSON data using JQuery?

I apologize for posing a seemingly simple query, but my understanding of JavaScript and JQuery is still in its early stages. The predicament I currently face involves retrieving JSON data from an external server where the information undergoes frequent ch ...

Tips for preventing duplicate entries in an AG Grid component within an Angular application

In an attempt to showcase the child as only 3 columns based on assetCode, I want to display PRN, PRN1, and PRN2. Below is the code for the list component: list.component.ts this.rowData.push( { 'code': 'Machine 1', &apo ...

The markers on Google Maps are currently displaying in the wrong position, despite the latitude and longitude being correct

Utilizing the Google Maps API, I have implemented a system to dynamically add map markers tracking 2 of our company's vehicles. The website is developed in asp.net c# mvc with bootstrap 4.3.1. An ajax request retrieves the latest marker location from ...

What is the best way to include a button at the bottom of a Material UI table?

I've been working with Material UI in React TypeScript and I'm having trouble adding a button at the bottom that leads to a form. Despite my attempts, I haven't been successful. Can someone please help me with this? I just need a simple butt ...

Error in Next.js Image Component: Missing SRC

Encountering an error with the next.js image component, specifically related to a missing "src" property. Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {} Th ...

Ruby on Rails allows for the selection of values in a dropdown menu to trigger the visibility of different sections of HTML

As a newcomer to Rails, I was able to successfully implement the onclick function for a f.checkbox element. Now, my challenge lies in achieving a similar functionality for a f.select element within a _form. Below is the code snippet that works for a chec ...

sending data from a callback to an express router

As I embark on learning node.js, I've encountered a challenging issue. In my passportAuth.js file, I create a user and have a callback to ensure the user is created successfully. The code snippet looks something like this: req.tmpPassport = {}; var ...

retrieving information from an array nested within a JSON object in an Angular application

I am struggling to retrieve two specific values from a JSON object. The content of the JSON is as follows: [ { "type":"session_start", "properties":[ { "property":"activity&q ...

What are the possible arguments for the event type onInput?

While diving into the world of html / javascript / vue, I stumbled upon the following code snippet. <input type="text" onInput="doAction(event);"> <script> var mesdata = { message: 'type your m ...

Utilizing import for Ionic3 to export const with logic

While developing an app using ionic3, I encountered an issue with setting up a proxy. When running in a browser, Ionic was able to recognize the path of my proxyUrl as shown below. ionic.config.json { "name": "myApp", "app_id": "", "v2": true, "t ...

What is the process of utilizing jQuery to hover over a relevant cell?

I'm interested in learning how to implement jQuery to highlight related tables. Initially, I explored this JS fiddle and discovered a method for highlighting both vertically and horizontally. I conducted several searches to find a similar approach, ...

Tips for eliminating unnecessary data in written content

Could anyone provide a recommended method for removing unnecessary symbols from text strings? For instance, transforming "CWC%20-%20Maint%20Eng%20-%20El" into the more readable format of "CWC - Maint Eng - El". ...

Is there a way to pass a token variable from the main page to an iframe without relying on a post message?

I am seeking assistance on how to transfer a variable from a parent window to an iframe. My situation is as follows: I am working with 2 Angular5 applications named A and B . Application B is loaded within Application A using an iframe. The aut ...

Error handling in Angular2 RxJS when using switchMap

Is there a way to properly manage errors that occur when calling this.authService.refreshToken()? How can I handle errors within the switchmap block or implement error handling in this scenario? post3(endpoint: string, body: string) : Observable<any& ...

Ember - Issue with Page Display

Currently tackling my first ember application, which consists of two pages: the Welcome page and a page displaying student details. To accomplish this, I have established two routes named index and studentdb. Unfortunately, I'm encountering an issue w ...

Adjust the image size without losing sharpness

I'm currently working on a web application for Minecraft and I am looking for a way to resize someone's skin without losing quality. I believe javascript might be the solution to this issue. ...

Unable to apply 3rd condition with ngClass into effect

I've been attempting to incorporate a third condition into my ngClass. Initially, I managed to get two classes working in my ngClass to change the row colors alternately. [ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0}" Now, I'm trying to introdu ...