0
0
Angularframework~5 mins

@ContentChild and content projection in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is content projection in Angular?
Content projection lets you insert content from a parent component into a child component's template. It helps create reusable components that can display different content.
Click to reveal answer
beginner
What does the @ContentChild decorator do in Angular?
@ContentChild finds a child element or directive inside the projected content of a component. It lets the component access and interact with that projected content.
Click to reveal answer
intermediate
How do you use @ContentChild to get a reference to a projected element?
You add @ContentChild with a selector (like a template reference variable or a component/directive type) in the child component class. Angular sets that property to the matching projected element.
Click to reveal answer
intermediate
Why is @ContentChild different from @ViewChild?
@ContentChild looks inside the content projected into the component (between its tags). @ViewChild looks inside the component's own template.
Click to reveal answer
intermediate
When is the @ContentChild property available during the component lifecycle?
The @ContentChild property is available after Angular runs the ngAfterContentInit lifecycle hook. Before that, it might be undefined.
Click to reveal answer
What does content projection allow you to do in Angular?
ARun code after the view initializes
BInsert external content into a child component's template
CCreate new Angular modules
DChange the component's CSS styles dynamically
Which decorator lets you access projected content inside a component?
A@ContentChild
B@ViewChild
C@Input
D@Output
When is the @ContentChild property guaranteed to be set?
AngOnInit
BngAfterViewInit
CngOnDestroy
DngAfterContentInit
What is the main difference between @ContentChild and @ViewChild?
A@ContentChild accesses projected content; @ViewChild accesses component's own template
B@ContentChild accesses inputs; @ViewChild accesses outputs
C@ContentChild is for services; @ViewChild is for directives
DThey are exactly the same
How do you select an element with @ContentChild?
ABy CSS selector only
BBy HTML tag name only
CBy template reference variable or directive/component type
DBy event binding
Explain how @ContentChild works with content projection in Angular.
Think about how a component can see content passed inside its tags.
You got /4 concepts.
    Describe a simple example scenario where you would use @ContentChild with content projection.
    Imagine a reusable panel component that needs to control a button passed inside it.
    You got /3 concepts.