Created
August 9, 2022 17:25
-
-
Save Burgov/20de8b23ead2a5f3c53ed8db4731b155 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'content-component', | |
template: '<div>Test {{ data }}</div>', | |
}) | |
export class ContentComponent { | |
@Input() data: string; | |
} | |
@Component({ | |
selector: 'child-component', | |
template: '<div>I have {{ childCount }} content children! Data: {{ childData|json }}</div><div><ng-content></ng-content></div>', | |
}) | |
export class ChildComponent implements AfterContentInit { | |
@ContentChildren(ContentComponent) children: QueryList<ContentComponent>; | |
childCount: number; | |
childData: string[]; | |
ngAfterContentInit() { | |
this.childCount = this.children.length; | |
this.childData = this.children.map(child => child.data); | |
} | |
} | |
@Component({ | |
selector: 'parent-component', | |
template: '<child-component><content-component *ngFor="let el of elements" [data]="el"></content-component></child-component>', | |
}) | |
export class ParentComponent { | |
elements = ['a', 'b', 'c', 'd', 'e']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment