Angular生命周期

Angular生命周期

初始化组件生命周期执行顺序

constructor
->ngOnChanges
->ngOnInit
->ngDoCheck
->ngAfterContentInit
->ngAfterContentChecked
->ngAfterViewInit
->ngAfterViewChecked
->ngOnDestroy

DOM事件setTimeout,setInterval,ajax均会触发所有组件

ngDoCheck->ngAfterContentChecked->ngAfterViewChecked

当父组件包含另一个子组件时

父: ngOnChanges->ngOnInit->ngDoCheck
子: ngOnChanges->ngOnInit->ngDoCheck->ngAfterContentInit->ngAfterContentChecked
父: ngAfterContentInit->ngAfterContentChecked
子: ngAfterViewInit->ngAfterViewChecked
父: ngAfterViewInit->ngAfterViewChecked

变化检测时

父: ngDoCheck
子: ngDoCheck->ngAfterContentChecked
父: ngAfterContentChecked
子: ngAfterViewChecked
父: ngAfterViewChecked
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容