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

junior

What is the minimum definition of a Component ?

middle

What is TestBed?

middle

How do you perform error handling in Observable s?

Bình luận

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

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