admin管理员组文章数量:1026192
I have an Ionic 2 application with a ParentComponent calling ChildComponent @ViewChild method to fire up multiple ChildComponents. One of the ChildComponents get's instantiated twice in the view with different parameters like so:
<ChildComponent [startFrom]="0" [limitTo]="1"></ChildComponent>
<ChildComponent [startFrom]="1" [limitTo]="1"></ChildComponent>
After an offline/online device state change, I call ChildComponent's method to update a list of items it returns.
@ViewChild(ChildComponent) childComponent: ChildComponent;
ngOnInit(): void {
thisworkService.connectSubscription(() => {
this.childComponent.getItems();
});
}
The issue here is this.childComponent
only get's hold of the first ChildComponent instance of the two.
Is there a way to iterate through multiple instances of the same @ViewChild ponent so I could do something like this.childComponent1.getItems()
and this.childComponent2.getItems()
?
Thanks for your help.
I have an Ionic 2 application with a ParentComponent calling ChildComponent @ViewChild method to fire up multiple ChildComponents. One of the ChildComponents get's instantiated twice in the view with different parameters like so:
<ChildComponent [startFrom]="0" [limitTo]="1"></ChildComponent>
<ChildComponent [startFrom]="1" [limitTo]="1"></ChildComponent>
After an offline/online device state change, I call ChildComponent's method to update a list of items it returns.
@ViewChild(ChildComponent) childComponent: ChildComponent;
ngOnInit(): void {
thisworkService.connectSubscription(() => {
this.childComponent.getItems();
});
}
The issue here is this.childComponent
only get's hold of the first ChildComponent instance of the two.
Is there a way to iterate through multiple instances of the same @ViewChild ponent so I could do something like this.childComponent1.getItems()
and this.childComponent2.getItems()
?
Thanks for your help.
Share Improve this question asked Apr 10, 2017 at 8:57 CyberRobotCyberRobot 7449 silver badges20 bronze badges1 Answer
Reset to default 6@ViewChildren(ChildComponent) childComponents: QueryList<ChildComponent>;
ngAfterViewInit(): void {
thisworkService.connectSubscription(() => {
this.childComponents.toArray();
});
}
I have an Ionic 2 application with a ParentComponent calling ChildComponent @ViewChild method to fire up multiple ChildComponents. One of the ChildComponents get's instantiated twice in the view with different parameters like so:
<ChildComponent [startFrom]="0" [limitTo]="1"></ChildComponent>
<ChildComponent [startFrom]="1" [limitTo]="1"></ChildComponent>
After an offline/online device state change, I call ChildComponent's method to update a list of items it returns.
@ViewChild(ChildComponent) childComponent: ChildComponent;
ngOnInit(): void {
thisworkService.connectSubscription(() => {
this.childComponent.getItems();
});
}
The issue here is this.childComponent
only get's hold of the first ChildComponent instance of the two.
Is there a way to iterate through multiple instances of the same @ViewChild ponent so I could do something like this.childComponent1.getItems()
and this.childComponent2.getItems()
?
Thanks for your help.
I have an Ionic 2 application with a ParentComponent calling ChildComponent @ViewChild method to fire up multiple ChildComponents. One of the ChildComponents get's instantiated twice in the view with different parameters like so:
<ChildComponent [startFrom]="0" [limitTo]="1"></ChildComponent>
<ChildComponent [startFrom]="1" [limitTo]="1"></ChildComponent>
After an offline/online device state change, I call ChildComponent's method to update a list of items it returns.
@ViewChild(ChildComponent) childComponent: ChildComponent;
ngOnInit(): void {
thisworkService.connectSubscription(() => {
this.childComponent.getItems();
});
}
The issue here is this.childComponent
only get's hold of the first ChildComponent instance of the two.
Is there a way to iterate through multiple instances of the same @ViewChild ponent so I could do something like this.childComponent1.getItems()
and this.childComponent2.getItems()
?
Thanks for your help.
Share Improve this question asked Apr 10, 2017 at 8:57 CyberRobotCyberRobot 7449 silver badges20 bronze badges1 Answer
Reset to default 6@ViewChildren(ChildComponent) childComponents: QueryList<ChildComponent>;
ngAfterViewInit(): void {
thisworkService.connectSubscription(() => {
this.childComponents.toArray();
});
}
本文标签: javascriptIterate through multiple ViewChild instances of the same component angular2Stack Overflow
版权声明:本文标题:javascript - Iterate through multiple @ViewChild instances of the same component angular2 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626199a2159875.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论