我知道我可以使用@ViewChildren
批注来访问DOM元素。但是,在这种特定情况下,entries
属性是在祖先组件(MenuComp
)中定义的。因此,我尝试使用queries
属性,如下所示:
@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
属性?
最佳答案
从angular 4.0.0-alpha + 1开始,如果您在父类的字段中使用@ViewChildren
,它将从父类继承注释。 queries
的Component
参数将消失。
关于inheritance - Dart :用查询替换ViewChildren,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39537405/