Hey there, I'm diving deeper into Angular and working on my first project. I am fetching data from my database using a service method:
getPost(postID: String) {
this.postDocument = this.db.doc('posts/' + postID)
return this.postDocument.valueChanges()
}
I am calling this method inside my component
ngOnInit() {
this.currentPost = this.route.paramMap.pipe(
switchMap((params: ParamMap) => this.fs.getPost(params.get('id')))
)
}
Everything is working fine so far, but I am struggling to display the data in my HTML. For instance, I am encountering an issue where it shows that 'title' is null even though it is displaying correctly.
<div>
post-read-page works!
<h1 *ngIf="currentPost">{{ (currentPost | async).title }}</h1>
</div>
Thank you in advance!
Exact Error:
ERROR TypeError: Cannot read property 'title' of null