Angular2 lifecycle hook

Angular2 lifecycle hook


angular2에서 제공되는 component lifecycle은 8개이다.

실행순서는 다음과 같다 
 1. ngOnChanges 
    input property의 값이 변경 되었을 때 실행
 
 2. ngOnInit 
    component 초기화시 사용 
    component 초기 값 설정시 가장 좋은 hook 

 3. ngDoCheck 
    모든 변경 사항에 대하여 실행 

 4. ngAgterCOntentInit 
    외부의 component를 불러오고 나서 최초 1회 실행(ng-content로 외부 component를        불러올 때..) 

 5. ngAfterContentChecked 
    외부의 component를 불러오고 나서 모든 변화에 실행 

 6. ngAfterViewInit 
    component의 view와 하위 component의 view가 초기화가 된 후 최초 1회 실행 
 7. ngAfterViewChecked 

    component의 view와 하위 component의 view가 초기화된 후 모든 변화에 실행(view뿐      만 아니라 property 변경, function 실행 등등)

8. onDestroy 
    component 혹은 directive가 제거 될 때 실행

댓글

가장 많이 본 글