Currently, I am exploring Angular 2 and encountered a situation where I set the variable isLoading to true initially, and then switch it to false after fetching required data. However, upon executing this process, I encountered the following error message:
In TypeScript - 'false' type cannot be assigned to 'true'
Here is the snippet of code causing the issue:
export class AppComponent implements OnInit {
isLoading: true;
constructor(private _articleService: ArticleService, private _postService: PostService){}
ngOnInit(){
this.articles = this._articleService.getArticles();
this._postService.getPosts()
.subscribe(posts => {
this.isLoading = false;
console.log(posts[0].title);
});
}