Reputation: 1277
i currently create a angular 2 app, but i ran into problems with QueryList.
How do i manage to get values out of it?
I get the querylist with:
@ViewChildren('setSlider') setSliders: QueryList<Slides>;
This part works fine so far. Now i got this object:
QueryList {_dirty: false, _results: Array[4], _emitter: EventEmitter}
And now.. i just want to get the second result from it.
For Example: setSliders[0] ---> dont work.
Whats the best way to do that?
thanks a lot :)
Upvotes: 0
Views: 923
Reputation: 657248
You can use this too.
ngAfterViewInit() {
console.log(this.setSliders.toArray());
this.setSliders.changes.subscribe(val => console.log(this.setSliders.toArray());
}
Upvotes: 2
Reputation: 4837
try using the map method:
this.setSliders.map( slider => console.log(slider.nativeElement) );
Upvotes: 1
Reputation: 5138
There are a few ways to do so. Check out API docs on Angular2 site: https://angular.io/docs/ts/latest/api/core/index/QueryList-class.html
The simplest way:
let secondSlide = this.setSliders.toArray()[2]
Upvotes: 3