cli*_*int 9 angular2-forms angular2-services angular
我一直在试图找出的意义ngAfterContentChecked(),并 ngAfterViewChecked()在一段时间.曾尝试过各种帖子,但仍无法理解其确切含义.以下是angular.io中给出的定义.有人可以用一些好的例子来解释它.
ngAfterViewChecked()- Respond after Angular checks the component's views and child views.
Called after the ngAfterViewInit and every subsequent ngAfterContentChecked().
A component-only hook.
ngAfterContentChecked()- Respond after Angular checks the content projected into the component.
Called after the ngAfterContentInit() and every subsequent ngDoCheck().
A component-only hook.
Run Code Online (Sandbox Code Playgroud)
假设我们有这个 Html
<div> // div A
<app-my-component>
<div>
this is some content for the component app-my-component
</div>
</app-my-component>
</div> // div B
Run Code Online (Sandbox Code Playgroud)
假设我们有这个组件
@Component({
selector: 'app-my-component',
template: `
<div> // div C
here is the View HTML but below we receive content html
<ng-content></ng-content>
</div> // div D
`
})
Run Code Online (Sandbox Code Playgroud)
在我们的组件中,从 div A 一直到 div B 就是视图。因此,AfterViewChecked 将在我们到达 B 时运行。内容是驻留在 ng-content 标记中的所有内容。因此,AfterContentChecked 将在我们到达 div D 时运行。但是,我的意思是对视图的任何更改都可以触发额外的 AfterViewCheck,这也应该触发 AfterContentCheck
| 归档时间: |
|
| 查看次数: |
1436 次 |
| 最近记录: |