I have a Reactive form like below:
this.personForm = this.fb.group({
firstname: [null, Validators.required],
lastname: [null, Validators.required],
home_id: [null],
home_name: [null, Validators.required],
})
I am retrieving the home list from DB using API and fill the mat-option accordingly, so far is okay, by the way I am displaying home_name value only, inside mat-select:
<mat-form-field class="full-width">
<mat-select placeholder="Select Home" formControlName="home_name">
<mat-option *ngFor="let home of homes" [value]="home.name">
{{ home.name }}
</mat-option>
</mat-select>
</mat-form-field>
now I want to post form values after submit, but I dont know how to update home_id when user clicks on home from dropdown menu ?
I tried:
<mat-select placeholder="Select Home"
formControlName="home_name"
(selectionChange)="setHomeId($event.value)">
but it is giving me home_name only,
I tried to put the same code inside <mat-option>
in order to get home object:
<mat-option *ngFor="let home of homes"
[value]="home_name"
(selectionChange)="setHomeId($event.value)">
but it seems <mat-option>
does not have function : (selectionChange)
(ngSubmit)
? – CruelEngine