@ContentChild
This is the documentation for Angular 7.
You can switch to the latest version Angular 10.
You can switch to the latest version Angular 10.
You can use ContentChild
to get the first element or the directive matching the selector from the content DOM. If the content DOM changes, and a new child matches the selector, the property will be updated.
Content queries are set before the ngAfterContentInit
callback is called.
Example
import {AfterContentInit, ContentChild, Directive} from '@angular/core';
@Directive({selector: 'child-directive'})
class ChildDirective {
}
@Directive({selector: 'someDir'})
class SomeDir implements AfterContentInit {
@ContentChild(ChildDirective) contentChild: ChildDirective;
ngAfterContentInit() {
// contentChild is set
}
}
Options
@ContentChild(
selector: Type<any>|Function|string,
opts?: {read?: any},
)
selector
#
selector: Type<any>|Function|string
opts
#
opts?: {read?: any}