124k views
0 votes
Which of the following statements is true about `ngOnChanges` and `ngOnDestroy` lifecycle hooks in Angular?

a) ngOnChanges is used for component initialization
b) ngOnDestroy is used to respond to input property changes
c) ngOnChanges provides information about changed input properties
d) ngOnDestroy is where we define input properties

1 Answer

6 votes

Final answer:

The ngOndChanges lifecycle hook is used to respond to input property changes and provides information about changed input properties. ngOnDestroy is used for performing cleanup when the component is destroyed.

Step-by-step explanation:

The correct statement about the ngOnChanges and ngOnDestroy lifecycle hooks in Angular is:

  1. ngOnChanges is used to respond to input property changes.
  2. ngOnDestroy is where we define input properties.
  3. ngOnChanges provides information about changed input properties.

The first option, "ngOnChanges is used for component initialization," is incorrect. Component initialization is typically handled in the ngOnInit lifecycle hook. The second option, "ngOnDestroy is used to respond to input property changes," is also incorrect. ngOnDestroy is used to perform any necessary cleanup when the component is destroyed, such as unsubscribing from subscriptions or clearing timeouts.

User Gby
by
8.0k points