Exploring arrays within objects with Angular

REACT:

this.countries = this.api.fetchAllCountries();

        this.countries.forEach(item => {
            this.countryData.push(item);
        });

VUE:

 <div v-for="country in countryData" 
        @click="displayCountryInfo(country)">
            {{ country.name }}
        </div>

ARRAY OF OBJECTS:

https://i.sstatic.net/EP3KQ.png

QUERY:

How can I display each country within the name property on its own button?

Answer №1

Simply add another iteration

<ion-item button detail lines="inset" *ngFor="let pais of paisesData" (click)="paisesInfo(pais)">
  <ul>
    <li *ngFor="let country of pais.response">{{ country }}</li>
  </ul>
</ion-item>

Answer №2

Populate the array with response data without using multiple loops in the template.

this.countries = this.api.getAllCountries();

    this.countries.forEach(country => {
        this.countryData.push(country.response);
    });

HTML:

 <ion-item button detail lines="inset" *ngFor="let country of countryData" (click)="countryInfo(country)">
        {{ country }}
    </ion-item>

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

Axios mandating the use of the "any" type for response type requirements

Currently, I am facing an issue while trying to retrieve data using Axios in my TypeScript React project. I have set the response type in axios to match CartItemType, however, Axios is enforcing the response type to be of CartItemType and any, which is cau ...

The Angular template loads and renders even before the dynamic data is fetched

I'm encountering a frustrating issue where the page loads before the data is retrieved. When I log the names in $(document).ready(), everything appears correct without any errors in the console. However, the displayed html remains empty and only shows ...

Improving type checking by extracting constant string values from a union type

I am exploring different types of employees: interface Employee { employeeType: string } interface Manager extends Employee { employeeType: 'MANAGER' // .. etc } interface Developer extends Employee { employeeType: 'DEVELOPER&apos ...

Angular custom filter with FabricJS

I am working with a binary/grayscale image and my objective is to filter the image so that all white color becomes transparent and all dark colors change to a specific user-defined color. I am facing challenges in creating a custom filter in Angular. I ha ...

Discovering and Implementing Background Color Adjustments for Recently Modified or Added Rows with Errors or Blank Cells in a dx-data-grid

What is the process for detecting and applying background color changes to the most recently added or edited row in a dx-data-grid for Angular TS if incorrect data is entered in a cell or if there are empty cells? <dx-data-grid [dataSource]="data ...

Leveraging local libraries with Angular

After setting up two local libraries: ng new my-library --create-application=false ng generate library core ng generate library shared The shared library utilizes the core library as shown below: import { CoreModule } from 'core'; @NgModule({ ...

Trouble with loading images on Angular Application

After successfully building and deploying my Angular App using the build command on the cli with the deploy-url option as shown below: ng b -deploy-url /portal/ I encountered an issue where everything in the assets folder was showing up as 404 not found ...

What is the best way to stop navigation when a button is clicked inside a table row that contains a routerLink?

Looking for a solution with an angular material table set up like this: <table mat-table [dataSource]="myTable" matSort> <ng-container matColumnDef="column1"> <th mat-header-cell *matHeaderCellDef>My Column</th> <td ma ...

What allows for array cells to go beyond the predefined array length?

During my debugging process, I came across an issue involving an integer array of size 0. In a test scenario, I experimented with an array that had more elements inputted than its actual length. int array[0]; for(int i = 0; i < 10; i++) array[i] = ...

Create a NfcV Write Lock Block instruction

Seeking to make data on a NXP ICODE SLIX SL2S2002 tag type 5 (ISO 15693) read-only by utilizing the WRITE SINGLE BLOCKS command through the NfcV object in an app based on Ionic: private readonly cmdISO15693 = { READ_SINGLE_BLOCK: 0x20, WRITE_SI ...

Utilizing a forwardRef component in TypeScript to handle child elements

Working with @types/react version 16.8.2 and TypeScript version 3.3.1. This forward refs example was taken directly from the React documentation with added type parameters: const FancyButton = React.forwardRef<HTMLButtonElement>((props, ref) => ...

Deploying Angular Micro Front Ends with Module Federation can lead to CORS errors

I am facing an issue with CORS error when trying to access the remoteEntry.js file from my two micro front end containers in a Docker environment. Everything works fine in local development, but running it in Docker causes this problem. Any advice on how ...

Accessing values from an array within a JSON object using jqGrid

Here is an example of my JSON data: [{"codDiretor":"123", "nomeDiretor":"Nome do Diretor", "data":"29/01/2014", "documentos":[{"codDocumento":"1", "nomeDocumento":"Primeiro Doc"}, {"codDocumento":"2","nomeDocumento":"Segundo Doc"}] ...

What is the best way to pass a value to a modal and access it within the modal's component in Angular 8?

How can I trigger the quickViewModal to open and send an ID to be read in the modal component? Seeking assistance from anyone who can help. Below is the HTML code where the modal is being called: <div class="icon swipe-to-top" data-toggle="modal" da ...

Removing an array from a specified property within a variable

Let's say I have an item $entity, and a property $property. The $property consists of multiple arrays inside it. I am trying to remove these arrays using the unset function like this: unset($entity->$property['array']); But unfortunat ...

Chrome reports "404 Not Found error: Cannot GET /" while using Angular 4 with Observable functions

I recently implemented observable data in my service, and it significantly improved the functionality of the application. https://i.sstatic.net/9h0KH.jpg This is an overview of my Service: import { Injectable } from '@angular/core'; import { H ...

Passing Down Instance Methods Using Static References in JavaScript/TypeScript

✋ Exploring the concept of access modifiers from TypeScript, how can we make it relevant for JavaScript developers as well? Let's consider a scenario where a parent class defines necessary members and a shared method: // ParentClass.js export defaul ...

What is the best way to retrieve only the second portion of these arrays in Swift 3?

In order to select 2 rows in a table, I am utilizing the following function: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { self.selectedCellTitle = self.communityPlayers[indexPath.row] cellId = indexPath.row ...

Is there a way for me to connect to my Firebase Realtime Database using my Firebase Cloud Function?

My current challenge involves retrieving the list of users in my database when a specific field is updated. I aim to modify the scores of players based on the structure outlined below: The Realtime Database Schema: { "users": { &quo ...

When it comes to form validations, I encounter an issue. I am able to view errors.minlength in the console, but for some reason, I am unable to access it

I would like the message "name is too short" to be displayed if last_name.errors.minlength evaluates to true. However, I encounter an error: Property 'minlength' comes from an index signature, so it must be accessed with ['minlength']. ...