There seems to be strange issue with ngModel. When you check out the example here: Plnkr
You see that when I try the limit the possible values from 1 to 5, resetting the input works always fine when entering a value higher than 5. Resetting to 1 works almost as well but does not so when the current value of the input is 1 or nothing. Then the ngModel behaves correctly but the input is not correctly updated.
Component class
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
...
<input type="text"
[(ngModel)]="testValue"
onClick="this.select();"
onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
</div>
`,
directives: []
})
export class App {
private changeValueTimeout;
private _testValue:number = 0;
private _testValueMax:number = 5;
get testValue() {
return this._testValue + 1;
}
set testValue(value: string) {
clearTimeout(this.changeValueTimeout);
var me = this;
this.changeValueTimeout = setTimeout(() => {
var numValue:number = Number.parseInt(value);
if (numValue > me._testValueMax - 1){
numValue = me._testValueMax;
} else if (numValue < 1 || isNaN(numValue)){
numValue = 1;
}
me._testValue = numValue - 1;
}, 1000);
}
constructor() {}
}
Is this a HTML specific issue is there a problem in angular2 or so?