I am currently trying to iterate through an array using *ngFor but nothing shows up on the page. This is the code for the HTML
<ion-header>
<ion-navbar>
<ion-title>
Recent News
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-card *ngFor="let article of articles">
<ion-card-content>
<h2>{{article.title}}</h2>
<p>{{article.description}}</p>
</ion-card-content>
</ion-card>
</ion-content>
<ion-footer>
<ion-toolbar>
<p>Powered by NEWS API</p>
</ion-toolbar>
</ion-footer>
The following is the code from the .ts (typescript?)
getNews() {
this.rest.getNews()
.then(result => {
this.news = result;
console.log(this.news);
});
}
The console log of this.news is this. However, if I console.log(this.news.articles[0]), this is the output instead.
Could it be done such that I iterate through from 0 to 9 instead of using ngFor or am I missing something?
EDIT: home.ts as follows
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { RestProvider } from '../../providers/rest/rest';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
news: any;
errorMessage: string;
constructor(public navCtrl: NavController, public rest:RestProvider) {
this.getNews();
}
getNews() {
this.rest.getNews()
.then(result => {
this.news = result;
console.log(this.news.articles[0]);
});
}
}