Lifecycle Hooks
OnInit
OnDestroy
DoCheck
OnChanges
AfterContentInit
AfterContentChecked
AfterViewInit
AfterViewChecked
Note
These interfaces have a method with the same name as the interface name, prefixed with “ng”.
OnInit
to execute logic after component’s data-bound properties have been initialized.
export class AppComponent implements OnInit {
ngOnInit() { }
}
OnDestroy
to execute clean up logic when a component is destroyed
OnChanges
to execute logic if any bindings have changed
AfterContentInit
to execute logic when a component’s content () has been fully initialized.
AfterContentChecked
to execute logic after every check of component’s content.
AfterViewInit
to execute logic when a component’s view has been fully initialized.
AfterViewChecked
to execute logic after every check of component’s view.
Last updated
Was this helpful?