[英]Angular 2: Resolve querylist?
i currently create a angular 2 app, but i ran into problems with QueryList. 我目前创建了一个angular 2应用程序,但是我遇到了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. 例如:setSliders [0] --->不起作用。
Whats the best way to do that? 最好的方法是什么?
thanks a lot :) 非常感谢 :)
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
在Angular2网站上查看API文档: https ://angular.io/docs/ts/latest/api/core/index/QueryList-class.html
The simplest way: 最简单的方法:
let secondSlide = this.setSliders.toArray()[2]
You can use this too. 您也可以使用它。
ngAfterViewInit() {
console.log(this.setSliders.toArray());
this.setSliders.changes.subscribe(val => console.log(this.setSliders.toArray());
}
尝试使用map方法:
this.setSliders.map( slider => console.log(slider.nativeElement) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.