I have the following service method in Angular 7:
public getTopPosts(): Observable<Payload<PostResponse>> {
return this.httpClient.get<Payload<PostResponse>>('/top-posts');
}
On the component I have:
export class TopPostsComponent implements OnInit {
posts: PostModel[] = [];
constructor(private postService: PostService) { }
ngOnInit() {
this.getPosts();
}
getPosts() {
this.postService.getTopPosts().subscribe((payload: Payload<PostResponse>) => {
this.posts = payload.map((response: PostResponse) => {
return {
id: response.id,
title: response.title
};
});
});
}
}
And the component HTML is:
<div *ngFor="let post of posts">
{{post.title}}
</div>
It is working but I would like to display "Loading" while data is loading.
Is this possible without using an extra variable on my component?