I have an HTML Div element with angular component children inside the div. Somehow the angular template is like this.
<mat-radio-group [(ngModel)]="selectedRadioValue">
<div
#radioButtonDiv
*ngFor="let opt of getInputPayload(); index as optIndex"
>
<mat-radio-button [value]="opt">
{{ opt.label }}
</mat-radio-button>
<ng-container *ngIf="someCondition === true">
<app-my-component [attr]="opt.foo"></app-my-component>
</ng-container>
</div>
</mat-radio-group>
I got the outer div element ref using @ViewChildren
@ViewChildren('radioButtonDiv') radioButtonDiv: QueryList<ElementRef<HTMLDivElement>>;
How do I access the <app-my-component> component class inside radioButtonDiv QueryList?
I tried to use querySelector() from the outer div's nativeElement.
this.radioButtonDiv.forEach((rbd, index) => {
if (index === findIndex) {
// Ignore the setTimeout.
setTimeout(() => {
const findChild = rbd.nativeElement.querySelector('app-formulir-medis-attribute');
}, 500);
}
});
However, findChild result in above code showing the nativeElement of <my-component> Component not the Angular component, thus I couldn't access its attributes and properties. How do I get the MyComponent class from the element ref above?
Thank you!