What are the lifecycle hooks ...
What are the lifecycle hooks ...
In Angular, lifecycle hooks are special methods that provide insights into the lifecycle of components and directives, allowing developers to perform custom operations at specific stages. Here’s a detailed overview of the lifecycle hooks available for both components and directives:
constructor(): This is the JavaScript class constructor for the component. It is used to inject dependencies but not for any Angular-specific logic.
ngOnChanges(): Called before ngOnInit()
and whenever one or more data-bound input properties change. The method receives a SimpleChanges
object containing current and previous property values[1][2][3].
ngOnInit(): Called once, after the first ngOnChanges()
. It is used for initial component initialization and setting up the component after Angular first displays the data-bound properties[1][2][3].
ngDoCheck(): Called during every change detection run, allowing you to implement custom change detection logic or do something on every check[1][2][3].
ngAfterContentInit(): Called after Angular projects external content into the component’s view. It is invoked only once after the first ngDoCheck()
[1][2][3].
ngAfterContentChecked(): Called after the content projected into the component has been checked, and it is called after every subsequent ngDoCheck()
[1][2][3].
ngAfterViewInit(): Called after Angular initializes the component's views and child views. It is called once after the first ngAfterContentChecked()
[1][2][3][12].
ngAfterViewChecked(): Called after the component's views and child views have been checked. It is invoked after every ngAfterContentChecked()
[1][2][3].
ngOnDestroy(): Called just before...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào