Angular生命周期
初始化組件生命周期執(zhí)行順序
constructor
->ngOnChanges
->ngOnInit
->ngDoCheck
->ngAfterContentInit
->ngAfterContentChecked
->ngAfterViewInit
->ngAfterViewChecked
->ngOnDestroy
DOM事件setTimeout,setInterval,ajax均會(huì)觸發(fā)所有組件
ngDoCheck->ngAfterContentChecked->ngAfterViewChecked
當(dāng)父組件包含另一個(gè)子組件時(shí)
父: ngOnChanges->ngOnInit->ngDoCheck
子: ngOnChanges->ngOnInit->ngDoCheck->ngAfterContentInit->ngAfterContentChecked
父: ngAfterContentInit->ngAfterContentChecked
子: ngAfterViewInit->ngAfterViewChecked
父: ngAfterViewInit->ngAfterViewChecked
變化檢測(cè)時(shí)
父: ngDoCheck
子: ngDoCheck->ngAfterContentChecked
父: ngAfterContentChecked
子: ngAfterViewChecked
父: ngAfterViewChecked