I have a component that renders its content based on an observable with async pipe.
<div *ngIf="equipment$ | async as equipment">
<button myDirective></button>
</div>
In the .ts file, I'm getting all of the MyDirective children. There can be any number.
@ViewChildren(MyDirective) actions!: QueryList<MyDirective>;
And then I want to access it in the ngAfterViewInit.
ngAfterViewInit(): void {
console.log(this.actions)
}
this logs a QueryList with 0 items. If I put the directive outside of my async pipe it all works perfectly:
<div *ngIf="equipment$ | async as equipment">
// Some HTML here
</div>
<button myDirective></button>
Is there any way I can retrieve the directives nested under the async pipe? I need to keep the ngIf because I have inputs bound to the equipment variable (which contains properties).
EDIT:
So, after thinking and thinking, I realized that what I'm trying to do here is to re-create NgRx. After all this time thinking it was too complicated, I now understand all the benefits it brings and the problems it solves. I'm gonna go ahead and try implementing it!