Angular7
My app.component has "noShow" variable which show/hides the element. Here is the app.component.html:
<div>
<strong *ngIf="!noShow" style="text-align:right;">
Welcome {{user ? user.username : ''}}
</strong>
<strong *ngIf="noShow" style="text-align:right;">
Hi {{user ? user.username : ''}}
</strong>
I am setting the value of "noShow" at app.component.ts but through receiving that a share message service implemented over 'rxjs/BehaviorSubject.
Here is the portion of app.component.ts:
export class AppComponent implements OnInit {
constructor(private _http: HttpClient, private _cdr: ChangeDetectorRef, private router: Router
, private share:ShareService) {}
public noShow: boolean = false
ngOnInit() {
this.share.currentMessage.subscribe(message=>this.noShow = message)
// blah blah
}
}
If the value of "noShow" is toggled, I receive:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: true'. Current value: 'ngIf: false'
I understand that this happens when view just load with initial value of noShow as False and then the value was changed immediately,however, no luck with resolving this issue.
This do not impact the view, it is working fine, but the error leaves bad taste when we see console logs in browser.
Thanks