Currently, I am facing an issue where I want to display a loading message for 3 seconds and then hide it using the *ngIf directive in Angular 8. Interestingly, I have not encountered this problem in my previous projects.
Below is the code snippet that I am utilizing:
//Component.ts
loading = true;
ngOnInit() {
setTimeout(()=> {
this.loading = false;
console.log(this.loading)
},3000)
}
//Component.html
<div *ngIf="loading" class="col-lg-12" style="text-align: center;">
<app-loading></app-loading>
</div>
After 3 seconds, the 'loading' variable is indeed set to false. However, the template fails to detect this change. Can someone explain why this is happening? Additionally, I would appreciate any suggestions on how to resolve this issue without resorting to using ChangeDetectorRef.