Angular TutorialLesson 27Free preview
Angular Lifecycle Hooks
This lesson is part of Angular · All levels
Summary
Each component has a life cycle from being made, rendered, to being destroyed. Hooks like ngOnInit are used to initialize data after the constructor, while ngOnDestroy is used to clean subscriptions. Understanding the life cycle helps you avoid memory leaks and misplaced logic.
Key points
- The constructor is called when the instance class is created
- NgInit is executed once the initial input is set
- NgOnDestroy is called when the component is removed
- NgOnChanges monitors changes in the @Input type of input
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.