QueryList changes subscribe does not work

Discussão em 'Angular' iniciado por István, Outubro 23, 2024.

  1. István

    István Guest

    I have a QueryList in a component. I am adding dynamically other components, that will be present in the QueryList, but if I subscribe to the changes of the QueryList, nothing happens. I thought it is because I subscribed in ngAfterViewInit, but the QueryList is undefined yet in ngOnInit.

    Here I have the plunkr.

    code:

    @Component({
    ...
    })
    export class AppComponent {

    @ViewChildren(ControlFactoryDirective) factories:
    QueryList<ControlFactoryDirective>

    ngAfterViewInit() {
    this.factories.changes.subscribe(() => {
    console.log('changed')
    })
    }
    }

    Continue reading...

Compartilhe esta Página