Hello,
new to ionic, i’m trying to build an app (ionic2,ng2,ts) with Http calls, every thing is working fine exept that view doesn’t update, i’ve tried a lot of things but never succeed.
Here is what i did, at first using a simple promise :
** api.service**
public getUserList(){
console.log('getUserList');
return this.http.post(this.buildURL('listUsers'), '', { headers: this.contentHeader })
.map(res => res.json());
}
userPage
public getDatas(){ // without | async pipe
this.api.getUserList().subscribe(
data => {
this.asyncItems = data;
},
err => this.errorGetDatas(err)
);
}
the view
<ion-item *ngFor="#item of asyncItems" (click)="openEditUser(item)">
{{item.id}} {{item.firstname}} {{item.lastname}}
</ion-item>
Works fine at init but don’t update, so i tried with async pipe
userPage
public getDatas(){
this.asyncItems = this.api.getUserList();
}
the view
<ion-item *ngFor="#item of asyncItems | async" (click)="openEditUser(item)">
{{item.id}} {{item.firstname}} {{item.lastname}}
</ion-item>
Works fine at init but don’t update, again, so i tried that way
** api.service**
public getUserListPromise(){
return this.http.post(this.buildURL('listUsers'), '', { headers: this.contentHeader })
.toPromise()
.then(res =>res.json() , this.handleError)
.then(data => { console.log(data); return data; });
}
userPage
public getDatas(){
this.asyncItems = this.api.getUserListPromise();
}
the view
<ion-item *ngFor="#item of asyncItems | async" (click)="openEditUser(item)">
{{item.id}} {{item.firstname}} {{item.lastname}}
</ion-item>
First i call getData() and it’s ok : view displays datas, then i try to edit datas (using a form in a modal) and here again every thing works fine (according to the console) and i call again getData() and here again datas are displayed in the console but the view still displays the initial values … Does someone can help me on this point? Is this a bug ? Did i missed something?