ViewChildren传递多个组件 [英] ViewChildren passing multiple components
本文介绍了ViewChildren传递多个组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我不能在@ViewChildren中传递多个组件?
Why can't I pass multiple components within the @ViewChildren?
当前拥有这个:
@ViewChildren(ColorFilterComponent, TransmissionFilterComponent)
public filters: QueryList<Filter>;
两个组件都实现了我的Filter接口:
Both components implements my Filter interface:
export declare abstract class Filter {
abstract applyFilter(vehicles: Vehicle): boolean;
}
在某个时候,我要遍历filters
并为viewChildren中的所有组件调用applyFilter()
方法.
At a certain point I am iterating through filters
and calling applyFilter()
method for all components within the viewChildren.
但是,当我做一个简单的日志时:
However when I do a simple log:
console.log(this.filters.toArray());
它仅包含一个过滤器.另一个不在这里.
It contains only one filter. The other one is not here.
在这种情况下,什么是最佳的最佳实践?
What would be a good best practice in this case?
推荐答案
HTML:
<colorfilter #filter></as-colorfilter>
<transmissionfilter #filter></as-transmissionfilter>
组件:
@ViewChildren('filter')
public filters: QueryList<Filter>;
这篇关于ViewChildren传递多个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文