i have a reactive form where i am trying the bind the option of the form from the ts file, i have an selectchange event listener on my mat-select which is triggering when i change or select an option in the Ui , but when i try to bind an option to the mat-select the selectchange event is not triggered , can anyone help me how do i trigger that
well tried this.form.get(formcontrolname).setvalue but which is not triggering the selectchnage event.
My mat-select element-----
<mat-select [formControlName]="this.getPropertyKey(property)"
(selectionChange)="selectChangeDetected($event, property)" [id]="getIdProperty(property)">
setting form option value from ts file as ----
this.form.get(aliasName)?.setValue(formattedValue);
function triggered when matselect change event is triggered
selectChangeDetected(event: MatSelectChange, property: { [key: string]: string }): void {
// my data manipulations
}
(selectionChange)
only take account when you change the select using click or by keyboard. It's like if you use the event(input)
or(keydown)
You need subscribe to valueChanges
You can also subscribe to any change in your form
Subscribing to form.valueChanges, you can check what "property" change using
Or (if you don't want the old value)
Update if only want to "listen" some changes, we can use some like
See stackblitz