Complete the code to import the lifecycle interface for content initialization.
import { Component, [1] } from '@angular/core';
The AfterContentInit interface is used to detect when projected content has been initialized.
Complete the code to implement the lifecycle hook method that runs after content projection.
export class ChildComponent implements AfterContentInit { [1]() { console.log('Content initialized'); } }
The method ngAfterContentInit runs after Angular projects external content into the component.
Fix the error in the lifecycle hook method name to correctly detect projected content initialization.
export class SampleComponent implements AfterContentInit { ngAfterContent[1]() { console.log('Projected content ready'); } }
The correct method name is ngAfterContentInit exactly, with 'Init' at the end.
Fill both blanks to correctly use @ContentChild and detect when projected content is initialized.
import { Component, AfterContentInit, [1] } from '@angular/core'; @Component({ selector: 'child-comp', template: '<ng-content></ng-content>' }) export class ChildComponent implements AfterContentInit { @[2]('projectedRef') projectedElement: any; ngAfterContentInit() { console.log(this.projectedElement); } }
The @ContentChild decorator is used to get a reference to projected content inside ngAfterContentInit.
Fill all three blanks to create a component that logs the text content of projected content after initialization.
import { Component, AfterContentInit, ContentChild, ElementRef } from '@angular/core'; @Component({ selector: 'proj-comp', template: '<ng-content></ng-content>' }) export class ProjComp implements AfterContentInit { @ContentChild('[1]') content!: ElementRef; ngAfterContentInit() { console.log(this.content.nativeElement.[2]); } }
The selector string for @ContentChild matches the template reference name. The textContent or innerText property gets the text inside the element.