1

I have one component that has this template:

    <div class="col-md-12 navbar navbar-fixed-bottom navbar-light bg-faded noselect">
    <ng-content></ng-content>
</div>

If i need get the childs inside <ng-content> i use @ContentChild(), but i need get a list of components that are inside a <ng-content>. How do this ?

Carlinhos
  • 940
  • 2
  • 10
  • 21
  • 1
    There is also `@ContentChildren()` – Günter Zöchbauer Nov 23 '16 at 18:04
  • Is it child or children? What are their types? – Meir Nov 23 '16 at 18:04
  • see also http://stackoverflow.com/questions/32693061/angular-2-typescript-get-hold-of-an-element-in-the-template/35209681#35209681 – Günter Zöchbauer Nov 23 '16 at 18:04
  • 1
    @GünterZöchbauer When i used `@ContentChild()` with one component was ok, but for get a list of components i needed use @ContentChildren(Component) components: QueryList, this resolved my problem. – Carlinhos Nov 23 '16 at 18:16
  • @GünterZöchbauer One more question... It's possible to remove one item of a QueryList ? If i make this, the item will be removed from the dom ? – Carlinhos Nov 24 '16 at 10:12
  • No, you can't modify `QueryList`. If you create the elements using `*ngFor`, then you can remove the item from the array you pass to `*ngFor` to get the element removed. – Günter Zöchbauer Nov 24 '16 at 10:22
  • I know this, but im not use `*ngFor`, im using `` and need remove elements. – Carlinhos Nov 24 '16 at 10:31
  • @GünterZöchbauer I dont know if this is sure, but im using `@ContentChildren (Component, {read: ElementRef}) components: QueryList `, and so is possible to use `remove ()` method from `nativeElement`. – Carlinhos Nov 24 '16 at 11:25
  • https://angular.io/docs/ts/latest/api/core/index/QueryList-class.html doesn't have a remove. if you use `this.components.toArray().remove()` then this doesn't change the `QueryList` but only the array returned by `toArray()` and this won't have any effect on the DOM or the `QueryList` itself. – Günter Zöchbauer Nov 24 '16 at 11:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128940/discussion-between-carlinhos-and-gunter-zochbauer). – Carlinhos Nov 24 '16 at 12:16

0 Answers0