相关疑难解决方法(0)

ViewChild和ContentChild的所有有效选择器是什么?

我正在寻找一个完整的有效选择器列表,我可以通过@ViewChild和来访问子组件/ DOM元素@ContentChild.

说我有一个孩子HelloComponent:

我知道我可以#ref为它添加模板和查询,如下所示:

<hello #myHello></hello>

@ViewChild('myHello') myHello: HelloComponent;
Run Code Online (Sandbox Code Playgroud)

或者我可以直接查找该组件(没有模板#ref):

@ViewChild(HelloComponent) myHello: HelloComponent;
Run Code Online (Sandbox Code Playgroud)

本期中,提到可以使用以下选择器:

我们目前支持CSS选择器的一个子集:
*元素选择器
*属性选择器(包括值)
*:not(...)伪选择器
*上面的组合(包括,)

但是当我在Stackblitz中测试这些以验证时(这是它的链接),我实际上无法让前三个中的任何一个工作.(检查控制台以查看undefined我无法工作的选择器类型.我不确定这些选择器是否出错或者实际列表是否不同.)

那么,哪些选择器会起作用?此外,在名单同样为@ViewChild,@ContentChild,@ViewChildren,和@ContentChildren

angular

28
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1