I want to change a value of a radio button based on another radio button, but the event is never triggered and i have no console error. So let's say i click on the Honda car at position 5, so the brand Civic should be selected automaticly at position 5 in the form.
I'm using Angular 5 and Material design 2.
Here's my template:
<mat-list>
<mat-list-item *ngFor="let id of ids">
<mat-radio-group>
<mat-radio-button name="car" value="honda" id="honda{{id}}" (change)="onChangeCar(id,honda)">Honda</mat-radio-button>
<mat-radio-button name="car" value="toyota" id="toyota{{id}}" (change)="onChangeCar(id,toyota)">Toyota</mat-radio-button>
</mat-radio-group>
<mat-radio-group>
<mat-radio-button name="brand" value="civic" id="civic{{id}}" (change)="onChangeBrand(id)">Civic</mat-radio-button>
<mat-radio-button name="brand" value="camry" id="camry{{id}}" (change)="onChangeBrand(id)">Camry</mat-radio-button>
</mat-radio-group>
</mat-list-item>
</mat-list>
In the controller i tried this, but the brand is never triggered :
@ViewChildren(MatRadioButton) rbuttons;
rbuttonsList: any[];
// This works
this.rbuttons.filter(x => x.id == 'brand13')[0].checked = true;
this.rbuttons.filter(x => x.id == 'brand131')[0].checked = true;
This give me en error : Cannot read property 'rbuttons' of undefined
// Get the ids that start with brand 13
this.rbuttonsList = this.rbuttons.filter(x => x.id.lastIndexOf('brand13', 0) === 0);
this.rbuttonsList.forEach(function (rbuttonIndex) {
this.rbuttons.filter(x => x.id == rbuttonIndex.id)[0].checked = true;
});