这是我的 html 模板代码:
<input type="text" maxlength="5"
[(ngModel)]="groupInfo.discount" (keyup)="validateFloat($event)">
有我的 validateFloat 方法:
validateFloat(event){
event.target.value = event.target.value.replace(/[^\d.]/g, "");
console.log(this.groupInfo.discount);
}
那么当输入值时:
12adc
输入元素输出值:
12
但 groupInfo.discount 值为:
12a
我不明白为什么 groupInfo.discount 值是12a
?
我怎样才能使 groupInfo.discount 值等于输入元素的值?
我的包依赖项:
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/forms": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",