a little hint: you do not have to create your promise on your own. You can add the additional toPromise function to an Observable, so you can call .toPromise() after your .map.
loadPost(){
this.postService.loadPost(this.id)
.then(data => {
this.post = data; //and this is the post variable
console.log(this.post); //I can see the post in here
this.hideLoading();
});
}
Here’s the console *I get it when I’m turn of the {{post.post.content}} from the HTML
I’m little confused with the promises and the async data… Because it can show the form even when the data is not ready (since it using the async method)
But, I don’t know the alternative of this “async” way… Anyway… Thanks for giving a info about toPromise But I hope I can stcik to the manual promise method (because that’s what I know from the Ionic 1 )
Did you mean this.post in my service not get the data ??
I don’t think so, because I can show it from this code in my post.ts file
loadPost(){
this.postService.loadPost(this.id)
.then(data => {
this.post = data; //and this is the post variable
console.log(this.post); //I can see the post in here
this.hideLoading();
});
}
I mean, that console.log(this.post); get the value from resolve(this.post) from my service, right ??
Templates are evaluated before asynchronous requests have completed. You must either initialize post with a sensible dummy or guard against the case where it is not yet defined in your template, using for example the Elvis operator.
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in build/pages/post/post.html:5:21
ORIGINAL EXCEPTION: TypeError: Cannot read property 'content' of null
But, when I’m turn off this code {{post?.post.content}} and add a console.log(this.post) on my loadPost function on my page.ts it show the object like this