ngOnChanges : Respond when Angular (re)sets data-bound input properties.
ngOnInit : Called once, Initialize the directive/component after Angular first displays the data-bound properties
ngDoCheck : Detect and act upon changes that Angular can't or won't detect on its own.
ngAfterContentInit : Angular calls after Angular projects external content into the component.
ngAfterContentChecked : After every check of component content.
ngAfterViewInit : Angular calls after it creates a component's child views.
ngAfterViewChecked : After every check of a component's views.
ngOnDestroy : Just before the directive is destroyed.
Hook method | Purpose | Timing |
---|---|---|
| Respond when Angular sets or resets data-bound input properties. The method receives a | Called before |
| Initialize the directive or component after Angular first displays the data-bound properties and sets the directive or component's input properties. See details in Initializing a component or directive in this document. | Called once, after the first |
| Detect and act upon changes that Angular can't or won't detect on its own. See details and example in Defining custom change detection in this document. | Called immediately after |
| Respond after Angular projects external content into the component's view, or into the view that a directive is in. | Called once after the first |
| Respond after Angular checks the content projected into the directive or component. | Called after |
| Respond after Angular initializes the component's views and child views, or the view that contains the directive. | Called once after the first |
| Respond after Angular checks the component's views and child views, or the view that contains the directive. | Called after the |
| Cleanup just before Angular destroys the directive or component. Unsubscribe Observables and detach event handlers to avoid memory leaks. See details in Cleaning up on instance destruction in this document. | Called immediately before Angular destroys the directive or component. |