我在组件中有一个QueryList
。我正在动态添加其他组件,这些组件将出现在QueryList
中,但如果我订阅了QueryList
的changes
,则不会发生任何情况。我认为这是因为我在ngAfterViewInit
订阅,但QueryList
是undefined
还在ngOnInit
。 Here I have the plunkr。QueryList更改订阅不起作用
代码:
@Component({
...
})
export class AppComponent {
@ViewChildren(ControlFactoryDirective) factories:
QueryList<ControlFactoryDirective>
ngAfterViewInit() {
this.factories.changes.subscribe(() => {
console.log('changed')
})
}
}
然后,我要补充的'ControlFactoryDirective'的'create'的'notifyOnChanges',但我无法在那里添加...我想在添加组件时检测更改 –