ngIf - Expression has changed after it was checked

后端 未结 6 1560
误落风尘
误落风尘 2021-02-01 12:37

I have a simple scenario, but just can\'t get it working!

In my view I display some text in a box with limited height.

The text is being fetched from the server,

6条回答
  •  萌比男神i
    2021-02-01 13:14

    For some reason, @Tiep Phan's answer didn't work for me to force change detection, but using setTimeout (which also forces change detection) did.

    I also only had to add it to the offending line, and it worked fine with the code I already had in ngOnInit instead of having to add ngAfterViewInit.

    Example:

    ngOnInit() {
        setTimeout(() => this.loadingService.loading = true);
        asyncFunctionCall().then(res => {
            this.loadingService.loading = false;
        })
    }
    

    More details here: https://github.com/angular/angular/issues/6005

提交回复
热议问题