77.9k views
2 votes
When does the ngAfterViewInit method typically run in Angular, and what does it respond to?

a) After ngAfterContentInit, responding to content projection
b) After ngDoCheck, responding to changes Angular can't detect
c) After Angular initializes the component's views, responding to view changes
d) During object creation, responding to DOM manipulations

1 Answer

4 votes

Final answer:

The ngAfterViewInit method is executed after Angular initializes a component's views, responding to view changes, and is where you can interact with DOM nodes.

Step-by-step explanation:

The ngAfterViewInit method typically runs after Angular initializes the component's views, which is a lifecycle hook in Angular that responds to the initialization and rendering of a component's child views and view children. So, the correct answer to when ngAfterViewInit runs and what it responds to is c) After Angular initializes the component's views, responding to view changes. This lifecycle hook is an ideal place for initialization work that requires the DOM nodes to be present and accounted for, such as querying DOM nodes or initializing third-party libraries that interact with the DOM.

User Philip Kendall
by
7.7k points