1
我知道我可以使用@ViewChildren
注释来访问DOM元素。但是,在这种特殊情况下,entries
属性在祖先组件中定义(MenuComp
)。于是,我就用queries
属性,如下所示:dart:通过查询替换ViewChildren
@Component(
selector: 'my-component',
template: '''
<ul>
<subentry-comp #entries *ngFor="let item of items" [item]="item"></subentry-comp>
</ul>''',
inputs: const <String>['items'],
queries: const <String, dynamic>{'entries': const ViewChildren('entries')})
class SubmenuComp extends MenuComp {}
但entries
仍然是空。我是否以错误的方式使用queries
属性?
从未见过前面提到的'quieries' ind'@Component()'。我知道构造函数参数的'@Query()'注释,但只要我使用Angular2(自alpha后期以来),它就被弃用了。您的查询似乎查询模板中的元素。我不明白这与“祖先”有什么关系 –
AFAIK @ @ @ ViewChild(ren)'和@ @ContentChild(ren)'建立在@ Query之上,我不希望'@ Query'做有很大的不同。 –