Stwosch
Stwosch

Reputation: 642

cant get content by ContentChildren

I'm in situation where I have a 'Items' component that has ng-content:

@Component({
 selector: 'items'
 template: `<ng-content></ng-content>`
})

I would like to get the value of this content, so that's why I'm using ContentChildren where I passed my 'Item' directive as selector.

@ContentChildren(Item) elements: QueryList<Item>;

Unfortunately I can't get any data.

Here I attach a link to plunker

In elements property I would like to have all elements from 'App' component that I've marked with 'Item' directive.

<items>
  <div item *ngFor="let num of nums">{{ num }}</div>
</items>

Am I doing something wrong?

Upvotes: 3

Views: 857

Answers (1)

yurzui
yurzui

Reputation: 214047

You have wrong selector for Item component. It should be

[item] because you use it as attribute

Forked Plunker

Upvotes: 3

Related Questions