ngIf - Expression has changed after it was checked

后端 未结 6 1500
误落风尘
误落风尘 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条回答
  •  醉梦人生
    2021-02-01 13:01

    Causing change detector to run after ngAfterContentChecked solved the problem for me

    example as below:

    import { ChangeDetectorRef,AfterContentChecked} from '@angular/core'
    export class example implements OnInit, AfterContentChecked {
        ngAfterContentChecked() : void {
            this.changeDetector.detectChanges();
        }
    }
    

    Although, as I read some of the articles, this issue gets solved in production mode without any required fix.

    Below is the possible reason for such issue:

    It enforces a uni-directional data flow: when the data on our controller classes gets updated, change detection runs and updates the view.

    But that updating of the view does not itself trigger further changes which on their turn trigger further updates to the view

    https://blog.angular-university.io/how-does-angular-2-change-detection-really-work/

提交回复
热议问题