我在組件中有一個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',但我無法在那裏添加...我想在添加組件時檢測更改 –