zoukankan      html  css  js  c++  java
  • [Angular] AfterContentChecked && AfterViewChecked

    AfterContentChecked & AfterViewChecked are called after 'OnChanges' lifecycle. And each time 'ngOnChanges' triggered, ngAfterContentChecked and ngAfterViewChecked will also be called. Which means we should be careful what we do in those lifecycle should be light weight, no havey calculation.

    AfterContentChecked:

    Here is the last chance you can modify the data before it rendered to the DOM. But there is one restriction that you cannot modify the data which passed to the content projection component:

    <course-card [course]="course">
        <course-image [image-url]="imageURL"></course-image>
    </course-card>
    ngAfterContentChecked () {
      this.course.description = 'something new'; // OK
      this.course.imageUrl = "" // error  
    }

    You cannot modify imageUrl prop since it is used by the content projection.

    AfterViewChecked:

    After the whole template has been checked, this lifecycle will be called, it means you cannot modify the @Input data any more. Otherwise it will throw error.

    Here what you can do is doing some DOM animation, foucs management... because DOM is already renderered to the screen.

  • 相关阅读:
    【2019/3/23】周进度报告
    第十周总结
    程序员修炼之道-从小工到专家阅读笔记01
    第九周总结
    用户模板和用户场景
    一维数组最大子数组续
    程序员的自我修养阅读笔记03
    第八周总结
    NABCD项目分析
    第七周总结
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10338404.html
Copyright © 2011-2022 走看看