How to listen for value changes from class property TypeScript - Angular

前端 未结 5 1211
情话喂你
情话喂你 2020-12-13 06:57

In AngularJS, we can listen variable change using $watch, $digest... which is no longer possible with the new versions of Angular (5, 6).

I

5条回答
  •  醉酒成梦
    2020-12-13 07:23

    You can import ChangeDetectorRef

     constructor(private cd: ChangeDetectorRef) {
              // detect changes on the current component
                // this.cd is an injected ChangeDetector instance
                this.cd.detectChanges();
    
                // or run change detection for the all app
                // this.appRef is an ApplicationRef instance
                this.appRef.tick();
    }
    

提交回复
热议问题