Lifecycle Hooks and Content Projection
Learn Lifecycle Hooks and Content Projection (Phase 3 · Components and Templates (Core), Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Lifecycle hooks • Angular creates, updates and destroys components, and calls lifecycle hook methods you implement. In order: constructor (inject dependencies only), ngOnChanges (an input changed), ngOnInit (once, after the first inputs: load data here), ngDoCheck , ngAfterContentInit/Checked , ngAfterViewInit/Checked (view and child components ready: DOM access), ngOnDestroy (clean up). • Newer APIs: afterNextRender() / afterRender() for DOM work, DestroyRef.onDestroy() for cleanup, effect() for reacting to signals.