I write a service return a promise, and in the component i call service and set model to data return from success function of promise the model is changed but GUI is not update. How can I solve this issues .
Service :
getPage(pageNo) {
return new Promise ((resolve, reject) {
this.http.get(this.dataGetPageUrl+"/" + pageNo)
.map(response => response.json())
.subscribe(
blocks => {
resolve(blocks);
},
error => console.log(error)
);
})
}
Component:
Service.getPage(1).then(function(data) {
this.model = data;
}).catch(function(error) {
})
Because of function
this.
doesn't point to the current class. Use ()=>
(arrow function) instead:
Service.getPage(1).then((data) => {
this.model = data;
}).catch((error) => {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.