Asking a question in stackoverflow for the first time. My ionic2 app has got an issue. I can get json in console ald, but when I want it show in my apps, news.html got some problem.
providers/news-data.ts
@Injectable()
export class NewsDataProvider {
data:any;
constructor(public http: Http) {
}
getUsers() {
if (this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.http.get('url').map(res => res.json()).subscribe(data => {
this.data = data;
resolve(this.data);
console.log('success');
});
});
}
}
news.ts
@IonicPage()
@Component({
selector: 'page-news',
templateUrl: 'news.html',
})
export class NewsPage {
users:any;
constructor(public navCtrl: NavController, public navParams: NavParams,public newsData:NewsDataProvider){
this.getUsers();
}
getUsers() {
this.newsData.getUsers().then(data => {
this.users = data;
});
}
}
news.html
<ion-header>
<ion-navbar color="danger" no-border-bottom>
<button ion-button menuToggle>
<ion-icon name="ios-contact"></ion-icon>
</button>
<ion-title></ion-title>
</ion-navbar>
<ion-toolbar no-border-top>
<ion-searchbar color="danger"
[(ngModel)]="queryText"
(ionInput)="updateSchedule()"
placeholder="Search">
</ion-searchbar>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-item *ngFor="let user of users">
{{user.title}}
</ion-item>
</ion-content>
console show
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. at NgForOf.ngOnChanges (common.es5.js:1689) at checkAndUpdateDirectiveInline (core.es5.js:10790) at checkAndUpdateNodeInline (core.es5.js:12216) at checkAndUpdateNode (core.es5.js:12155) at debugCheckAndUpdateNode (core.es5.js:12858) at debugCheckDirectivesFn (core.es5.js:12799) at Object.eval [as updateDirectives] (NewsPage.html:22) at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12784) at checkAndUpdateView (core.es5.js:12122) at callViewAction (core.es5.js:12485)
but can get data in Network there ald