我想使用多个离子载玻片 https://ionicframework.com/docs/api/components/slides/Slides/我动态添加的。但我不能使用@viewChild
。请提出解决此问题的方法。
模板.html:
<div *ngFor="let name of title;let i = index;">
<ion-slides id="something" #slides>
//some code
</ion-slides>
</div
组件.ts:
@ViewChild('slides') slides: QueryList<Slides>;
....
ngAfterViewInit(){
setTimeout(()=>{
alert(this.slides.toArray()); //this line rise error
}, 3000);
}
Error :
_this.slides.toArray 不是一个函数
Use @ViewChildren
代替@ViewChild
, 阅读更多 https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e
@ViewChild https://angular.io/api/core/ViewChild#viewchild :
您可以使用 ViewChild 获取第一个元素或指令
匹配视图 DOM 中的选择器。
@ViewChildren https://angular.io/api/core/ViewChildren#viewchildren :
您可以使用 ViewChildren 来获取元素的 QueryList 或
来自视图 DOM 的指令。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)