I got a formControl passed in @Input
parameter that is bounded to input of number type that maximum value should be 10.
When user types number that is bigger it should not change input value.
What is the way to either prevent event propagation or get old value and set it again?
I tried many other solutions from stack and github, but nothing solves my problem.
valuecontrol: FormControl = new FormControl(0);
constructor(){
this.control.valueChanges.pipe(distinctUntilChanged()).subscribe(newValue=>{
if(newValue >= 10){
// set previous value
const oldValue = this.control.value;
console.log("old value = ", oldValue)
this.control.patchValue(oldValue);
}
})
}.
DEMO: https://stackblitz.com/edit/angular-6ocjfj?file=src/app/app.component.ts