【发布时间】:2017-08-28 06:01:19
【问题描述】:
我在一个组件中有一个QueryList。我正在动态添加其他组件,这些组件将出现在QueryList 中,但是如果我订阅QueryList 的changes,则不会发生任何事情。我以为是因为我订阅了ngAfterViewInit,但QueryList 是undefined 而在ngOnInit。
代码:
@Component({
...
})
export class AppComponent {
@ViewChildren(ControlFactoryDirective) factories:
QueryList<ControlFactoryDirective>
ngAfterViewInit() {
this.factories.changes.subscribe(() => {
console.log('changed')
})
}
}
【问题讨论】:
标签: angular typescript eventemitter