Apr 24, 2023
Angular basic interview question What are the life cycle hooks in angular components? #angularMantra
Life cycles hooks are different phases of existing in our component between creation and destroying
- ngOnChanges — called before onInit if component have input / output and change happens
- ngOnInit — called once
- ngDoCheck — called every time change(event, click..etc) happens(change detection runs) alias as custom change detection
- ngAfterContentInit — called once after content initialise
- ngAfterContentChecked — called first time after ContentInit then successive ngDoCheck
- ngAfterViewInit — called once after first after content Checked and view initialised
- ngAfterViewChecked — called first time after View initialised post that successive content Checked
- ngAfterDestroy — called just before component destroy