ContentChildren class
Declares a reference to multiple child nodes projected into <ng-content>
.
The annotated List is replaced when the DOM is updated.
Example
@Component(
selector: 'root-comp',
directives: [TabPanelComponent, TabComponent],
template: '''
<tab-panel>
<tab-comp></tab-comp>
<tab-comp></tab-comp>
<tab-comp></tab-comp>
</tab-panel>
''',
)
class RootComponent {}
@Component(
selector: 'tab-comp',
template: 'I am a Tab!',
)
class TabComponent {}
@Component(
selector: 'tab-panel',
template: '<ng-content></ng-content>',
)
class TabPanelComponent implements AfterContentInit {
@ContentChildren(TabComponent)
List<TabComponent> tabs;
@override
void ngAfterContentInit() {
for (var tab in tabs) {
// Do something.
}
}
}
See ViewChildren for a full documentation of parameters and more examples.
WARNING: There is a known issue (b/129297484) where, when used in
combination with an NgFor
(or a custom directive that supports moving
embedded views) this field or setter may not be updated. For details see
go/angular-dart/dev/template-queries.
- Annotations
-
- @Target({TargetKind.field, TargetKind.setter})
Constructors
- ContentChildren(Object selector, {bool descendants = true, Object? read})
-
const
Properties
- descendants → bool
-
Whether to query only direct children (
false
) or all children (true
).finalinherited - first → bool
-
Whether to only query the first child.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- read → Object?
-
The DI token to read from an element that matches the selector.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selector → Object
-
Either the class Type or selector String.
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited