• [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.

  • 相关阅读:
    第三周学习进度
    四则运算之结对开发
    第二周学习进度
    单元测试
    构建之法阅读笔记03
    本周学习进度
    四则运算三
    构建之法阅读笔记02
    本周学习进度
    按照Right-BICEP要求设计的测试用例
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10338404.html
Copyright © 2020-2023  润新知