Using ngFor to structure columns without displaying any data

Recently, I started working with ionic/angular and encountered a problem with ngFor. Although the ngFor loop seems to create columns and cards as expected, the data from my items array is not showing up in the cards. It's puzzling why the columns/cards are being generated but the {{items.key}} data isn't being rendered. Any assistance on this issue would be highly appreciated!

(By the way, this happens to be my first question here, so please inform me if there are any incorrect tags or errors)

The HTML file looks like this:

<ion-content>
<ion-grid>
<ion-row wrap>
  <ion-col *ngFor="let item of items" >
    <ion-card>
      <img src="assets/icon/tuneImage.png" />
      <ion-card-header>
        <ion-card-subtitle></ion-card-subtitle>
        <ion-card-title>{{items.key}}</ion-card-title>
      </ion-card-header>
      <ion-card-content>
      </ion-card-content>
    </ion-card>
  </ion-col>
</ion-row>
</ion-grid>
</ion-content>

The .ts file contains the following:

export class Page2Page implements OnInit {
 public items:any;
 data: Observable<any>;

  constructor(public http: HttpClient) { }

  ngOnInit() {
        var url = 'https://thesession.org/tunes/new?format=json';
        this.data = this.http.get(url);
        this.data.subscribe(data =>{
        this.items  = Object.assign([], data.settings);
        //console.log(this.items[1].key);
        })
        }
  } 

Attached below is an image showing the current state of the cards that fail to display the {{items.key}} value.

Answer №1

The key belonging to each individual item, not to the entire array, should be referenced as item.key instead of items.key.

Avoiding the widespread use of the any type is highly recommended. Implementing the appropriate types would clarify this issue further. Compiling in AOT mode may even result in an error message rather than blank output.

Answer №2

There are a couple of important points to consider.

(i) When working with data that is returned as an array, it's essential to correctly assign the settings and ensure you are binding the data using the appropriate type. To simplify this process, you can use a tool like JSON2TS to generate a model for your data type.

  this.items  = data.settings;

(ii) It's crucial to reference item.key instead of items.key since the object you are looking for is within the item.

<ion-col *ngFor="let item of items" >
    <ion-card>
      <img src="assets/icon/tuneImage.png" />
      <ion-card-header>
        <ion-card-subtitle></ion-card-subtitle>
        <ion-card-title>{{item.key}}</ion-card-title>
      </ion-card-header>
      <ion-card-content>
      </ion-card-content>
    </ion-card>
</ion-col>

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

The function you are trying to call is not callable. The type 'Promise<void>' does not have any call signatures. This issue is related to Mongodb and Nodejs

Currently, I am attempting to establish a connection between MongoDB and Node (ts). However, during the connection process, I encountered an error stating: "This expression is not callable. Type 'Promise<void>' has no call signatures" da ...

Converting multiple tiff image files into a single image in Angular 9: A step-by-step guide

I am currently developing a web application using Angular 9. I am looking to incorporate a feature that will enable the conversion of multiple Tiff images into a single PDF or window.URL.createObjectURL(blob) of pdf. let images = ["http://netghost.nar ...

Adapting Angular HTTP requests for seamless integration with Azure's app service in the MEAN Stack Environment

After deploying my app to the app service, I encountered a 502 bad gateway error when attempting to log in. While testing locally, I am able to login using http://localhost:3000/api/user/login. As this is my first time deploying to the cloud, I assumed rep ...

Comparison of Angular 2 Load Times on Desktop and Mobile Devices

I'm currently working on a webpage using Angular CLI and bootstrap version 4. I'm facing an issue specifically with the load times when accessed on mobile devices. Interestingly, the page loads in less than a second on desktop but takes over 10 s ...

Declaring a sophisticated array as a property within another property in Typescript

As a newcomer to Angular and Typescript, I am facing a challenge while declaring a property with a complex array as one of its values. Here is what I have attempted: groupedItem: { customGroupId: string, cgName: string, category: [{ cu ...

Create and save data to a local file using Angular service

I am facing an issue with my Angular service: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { person } from '../interfaces/iperson ...

Implementing authentication using http.post in Angular 2 with Django-Rest-Framework

I have spent more time than I care to admit trying to find a solution to this particular issue, but unfortunately, I am unable to resolve it on my own. Currently, I have a Django-rest-api that I set up using this tutorial. I can successfully interact with ...

Accessing information necessitates two separate subscriptions

I am posting this inquiry in order to enhance my understanding. Below is an excerpt from my service: export class HomeService { private generalstatistics = new ReplaySubject<object>(); constructor( private http: HttpClient ) { this ...

Cypress symbolizes the logical OR condition within a repeating loop

I am currently facing a challenge with testing the input values of a table. I am struggling to represent the OR condition and skipping a specific cell within the table. The table is cyclic in nature, where all values are positive except for one cell that a ...

Establish a connection to Cosmos DB from local code by utilizing the DefaultAzureCredential method

I've created a Typescript script to retrieve items from a Cosmos DB container, utilizing the DefaultAzureCredential for authentication. However, I'm encountering a 403 error indicating insufficient permissions, which is puzzling since I am the ad ...

Using Angular 8 to Pass Form Data to Another Component via a Service

Is there a way to send all the Formgroup data as a Service in Angular to Another Component without using ControlValueAccessor? I want the receiver to automatically receive the value data whenever someone enters information on a form. I am attempting to mo ...

Conceal the ion-tabs in an ionic framework

I have been implementing a solution to hide ion-tabs by following this codepen example: <ion-tabs ng-class="{'tabs-item-hide': hideTabs}"> // --> my tabs content </ion-tabs> <ion-view hide-tabs> // --> my content ...

How can we restrict the type without altering the original type?

import { CSSProperties } from 'react'; type StyleRulesType = Partial<CSSProperties> type StylesDefinition = { [key: string]: StyleRulesType }; const styles: StylesDefinition = { list: { position: 'relative', }, ...

Use patchValue to assign a value and make the field inactive

After loading a list and pushing it into a FormArray, I am in need of dynamically setting the disabled property for certain fields. My question is: Can I achieve this by using only the patchValue method? I attempted something like this.rowArray.controls[i ...

Is the TypeScript Callable interface unable to be called?

I am currently in the process of developing a customized version inspired by ts-optchain. The main goal is to create a functionality that produces a duplicate of the original object with specific modifications incorporated without altering the original obj ...

`Adjusting video frame on canvas`

When I capture video from a user's camera and display it in a 1:1 square, I encounter an issue when trying to draw the picture to a canvas. The image is not drawn in the same location on the canvas. How can I resolve this problem? To see a live examp ...

Enhance typescript interfaces with third-party library components in React.js

As a newcomer to typescript, I am in the process of converting my existing react project to use typescript. After changing my files to tsx, I encountered several errors which I managed to resolve except for one type-related issue that I couldn't find ...

Xcode 12.4 error: 'Notifications cannot be enabled' in Ionic 5

Since the Xcode 12.4 update, the Firebase Push Notifications have ceased functioning properly, displaying the error message "Notifications are not allowed for this application". I have made sure to update all Ionic, Angular, and Capacitor packages to the ...

What steps should I take to modify the date format to "dd / mm / yy"?

When using 'toISOString ()' in JavaScript, it appears as shown in photo 2. How can I modify this format? Note: I am working with AngularJs. Image 1 is located in list.component.ts Additional documents: Image 1 Image 2 Image 1: formatDate(e) ...

Arranging an array containing three elements

As I work on my angular app, I have come across the following array: [ { "Name": "Jack", "IncomingTime": "2020-06-19T11:02+00:00", "Outgoingtime": "2020-06-19T11:07+00:00" ...