I'm working on a scenario where I want the ngModel
to get update based on certain conditions
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;
}
}
On the first attempt to change the value to something greater than 10, the view updates. But subsequent changes don't. What causes this behavior and how does one work around this?
Do not do this ...
do this ...