angularjs双向绑定数据input输入多个小数点问题(双向绑定不刷新的问题)
文章目录
1.引入ChangeDetectorRef组件
import {ChangeDetectorRef} from '@angular/core'; constructor(public changeDetectorRef:ChangeDetectorRef) {}2.页面代码
<input type="text" placeholder="0.00" \[(ngModel)\]="item.TMP\_STOCK" (ngModelChange)="inputRule('stock',$event)"/>3.当输入框发生改变时执行下列方法
//当ngModel发生改变时触发方法
inputRule(name, event) {
//当输入框输入1...系统默认认为只有1.此时ngModel不发生任何改变所以这时候需要我们手动进行改变
this.item.TMP\_STOCK = null;
//detectChanges() - 从该组件到各个子组件执行一次变化检测
this.changeDetectorRef.detectChanges();
//最后给ngModel赋值
this.item.TMP\_STOCK = this.pubtool.numRule(event);
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论