Skip to main content

Content and view hooks

Learn Content and view hooks (Module 9 · Component Lifecycle, Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Content vs view • Imagine a photo frame . The frame (your component) has its own parts (its view : template and child components). Someone can also slide a picture into it from outside ( content projected with <ng-content> ). • ngAfterContentInit() runs once after the projected content is ready. ngAfterViewInit() runs once after the component's own template and its children are rendered. • The Checked variants ( ngAfterContentChecked , ngAfterViewChecked ) run after every change detection pass, so they run very often. • Rule of thumb: need a @ViewChild element? Use ngAfterViewInit. Not before:...

More lessons in Module 9 · Component Lifecycle