Moh*_*deh 2 angularjs angularjs-scope angular angular6
我们$scope.$apply()在angularjs中执行了正确的angularjs范围生命周期。
Angular 6中有与此等效的东西吗?
在构造函数中注入
constructor(private ref: ChangeDetectorRef) {
}
Run Code Online (Sandbox Code Playgroud)
并打电话
this.ref.detectChanges();
Run Code Online (Sandbox Code Playgroud)
您可以注入ChangeDetectorRef并将其用于手动运行更改检测。它具有为该组件运行更改检测或停止它的方法。您可以探索ChangeDetectorRef查看上述链接的方法。
import { ChangeDetectorRef } from '@angular/core';
@Component({
...
})
export class MyComponent {
constructor(private changeDetector: ChangeDetectorRef ) {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3394 次 |
| 最近记录: |