【发布时间】:2018-04-14 17:02:14
【问题描述】:
我followthese 实现ViewChildren,但我无法得到孩子。为什么?
@ViewChildren(TextField) inputs: QueryList<TextField>;
ngAfterViewInit(): void {
console.log('this.inputs.length = ', this.inputs.length);
// the length is 0
}
DEMO
【问题讨论】:
-
无法查询TextField,尝试使用模板引用变量
<TextField #ref></TextField>和组件@ViewChildren('ref') inputs: QueryList<ElemenetRef>; -
@yurzui - 为什么我们不能查询
TextField's? -
The Angular api 查询组件类名
@ViewChildren(Pane) ...。 -
@ViewChildren(Pane)正在工作,因为Pane是类而不是选择器。在您共享的链接中,它在Metadata Properties>“选择器 - 用于查询的指令类型或名称”下说明。 -
@ConnorsFan 请参阅下面的答案
标签: angular nativescript angular2-nativescript