'Angular runtime created components aren't listed in @ViewChildren

As you can see in this example (https://stackblitz.com/edit/angular-ivy-knbzcs?file=src%2Fapp%2Fapp.component.html) Angular doesn't seam to list runtime created components (via viewContainerRef.createComponent(HelloComponent)) in it's @ViewChildren(HelloComponent).

Is this an expected behavior or a bug? Do I need to mark it somehow so it get's listed?

Edit: just updated the example. Sorry, was a broken version so no chance to comprehend! As you can see now, the dynamic components aren't counted.



Solution 1:[1]

in general a QueryList is mannaged subscribing to changes observables, some like

  @ViewChildren(HelloComponent) helloComponents:QueryList<HelloComponent>

  ngAfterViewInit()
  {
    this.helloComponents.changes.pipe(startWith(null)).subscribe(res=>{
      this.helloCount=this.helloComponents.length
    })
  }

NOTE: I use the rxjs/operator startWith to allow at first execute the action.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eliseo