Câu hỏi phỏng vấn Angular
Câu hỏi

What are the lifecycle hooks ...

Câu trả lời

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:

Lifecycle Hooks for Components

  1. constructor(): This is the JavaScript class constructor for the component. It is used to inject dependencies but not for any Angular-specific logic.

  2. 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].

  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].

  4. ngDoCheck(): Called during every change detection run, allowing you to implement custom change detection logic or do something on every check[1][2][3].

  5. ngAfterContentInit(): Called after Angular projects external content into the component’s view. It is invoked only once after the first ngDoCheck()[1][2][3].

  6. ngAfterContentChecked(): Called after the content projected into the component has been checked, and it is called after every subsequent ngDoCheck()[1][2][3].

  7. ngAfterViewInit(): Called after Angular initializes the component's views and child views. It is called once after the first ngAfterContentChecked()[1][2][3][12].

  8. ngAfterViewChecked(): Called after the component's views and child views have been checked. It is invoked after every ngAfterContentChecked()[1][2][3].

  9. ngOnDestroy(): Called just before...

senior

senior

Gợi ý câu hỏi phỏng vấn

senior

Why would you use lazy loading modules in Angular app?

junior

How would you protect a component being activated through the router?

junior

What is a Service, and when will you use it?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào