I will explain my problem with a simplified example since my code is quite lengthy.
I want to display a certain div when either one of isFetching or isDownloading is true.
<div *ngIf="(isFetching || isDownloading)">
My div element is here
</div>
In the start of my program both of them are true, so the div should be displayed. Below the div from above, I have other elements which are displayed on the view after isFetching is changed to false. (isFetching is changed to false after the fetching from the database has completed.) After isFetching is changed to false and the elements are rendered, after the last element of these is downloaded (it is an image), I then change isDownloading to false.
When both isFetching and isDownloading are false, this is when I want to hide the div element.
However, the code I just explained, gives me this error:
Expression has changed after it was checked. Previous value: 'ngIf: true'. Current value: 'ngIf: false'.
I do not seem to understand why do I get this issue? What is wrong with my logic? How can I achieve the desired result without getting this error?
EDIT:
This code is in the constructor of my class:
firebase.database().ref('/users/' + this.userId).once('value').then(function(snapshot) {
this.username = (snapshot.val() && snapshot.val().username) || 'Anonymous';
this.isFetching = false;
});
After isFetching is changed to false. There are other elements in my .html which get rendered. And then this code is called after the last element (which is an image) of those elements is loaded (load)="latestElementLoaded()".
latestElementLoaded(){
this.isDownloading = false;
}