Render a Observable object property in Angular template

I have the following Angular 7 component:

export class PostComponent implements OnInit {

  post$: Observable<PostModel>;

  constructor(private postService: PostService) { }

  ngOnInit() {$ = postService.getPostById(25);



On the component template I used the following:

<p>Title: {{post$.title}}</p>

Title shows empty and I think is because post$ is an Observable.

When using arrays, e.g. posts$: Observable<PostModel[]> I pass the observable to the template and it works fine using ngFor.

But how should I do it in this case?

Source: Angular

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.