I'm currently working on a situation where I need the ngModel
to be updated based on specific conditions.
Here is the template:
<mat-form-field>
<mat-label>val:</mat-label>
<input matInput [(ngModel)]="someVal" (ngModelChange)="onChange($event)">
</mat-form-field>
Component:
someVal: number = 10;
onChange(val: number):void {
if(val > 10){
this.someVal = 0;
}
}
After attempting to change the value to something greater than 10 for the first time, the view updates. However, subsequent changes do not reflect in the view. What could be causing this behavior and how can it be resolved?