#ng-content and contentChildren
5 messages · Page 1 of 1 (latest)
contentChildren(".myClass"); is not correct. If you pass a string to contentChildren (let's say 'foo'), then it looks for elements in the projected content marked with a template variable named foo, i.e. something like <div #foo>.
Also, you can't project several different things with ng-content.
I'm not sure about what do u want to do properly but do you have a root inner DOM? If yes, you could use:
@Component({
selector: 'upper',
template: <ng-content></ng-content>
})
export class UpperComponent {
@Input
content: String;
@ContentChild(...)
element: any;
}
And catch like:
@Component({
selector: 'upper',
template: <div #foo> <ng-content></ng-content> </div>
})
export class UpperComponent {
@ViewChild('foo') content: ElementRef;
I hope you can do it. Good afternoon.