I have a component as follows:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app',
moduleId: module.id,
template: `
<input [value]="a" (change)="onValidateOfA($event)" />
`,
})
export class AppComponent implements OnInit {
a: number = 10;
constructor() { }
ngOnInit() {
}
onValidateOfA(e: any) {
let t = e.target.value * 1;
if (t < 10) {
t = this.a;
}
this.a = t;
}
}
The logic is simple. I would like to switch to previous value in the textbox when the user types any value less than 10. The value gets changed in variable "a", but not getting reflected in textbox (using property binding). The value in textbox does not always represent the same value in 'a' (or how to force as such in this case).
I am kind of learning detection changes in Angular and would like to resolve the problem using that rather than trying to solve the problem in a very different approach.
I tried to follow everything mentioned at following:
But with no luck or I am missing something (no error, just simply the same problem).