Fargho
Fargho

Reputation: 1277

Angular 2: Resolve querylist?

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

Answers (3)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

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

ryanrain
ryanrain

Reputation: 4837

try using the map method:

this.setSliders.map( slider => console.log(slider.nativeElement) );

Upvotes: 1

RomanHotsiy
RomanHotsiy

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

Related Questions