加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

ngAfterContentChecked()不可理解的角度2

发布时间:2020-12-17 07:21:48 所属栏目:安全 来源:网络整理
导读:我一直试图弄清楚ngAfterContentChecked()和ngAfterViewChecked()的含义.曾尝试过各种帖子,但仍无法理解其确切含义.以下是angular.io中给出的定义. 有人可以用一些好的例子来解释它. ngAfterViewChecked()- Respond after Angular checks the component's vi
我一直试图弄清楚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.
假设我们有这个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

假设我们有这个组件

@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
  `
})

在div中我们的组件一直到div B,即View.因此,当我们到达B时,AfterViewChecked将运行.内容是ng-content标记中的所有内容.所以AfterContentChecked将在我们到达div D时运行.但是任何我意味着对视图的任何更改都可以触发一个额外的AfterViewCheck,它也应该触发AfterContentCheck

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读