我有一个指令,它通过ngModelCtrl操作输入字段的$ viewValue。$ setViewValue()模糊。
function _onFocus () {
presentation = false;
if(!ctrl.$isEmpty(ctrl.$modelValue)) {
ctrl.$setViewValue(String(ctrl.$modelValue).replace(/\./, ','));
ctrl.$render();
}
}
由于这只是外观,我想知道是否有可能设置ViewValue而不改变输入字段本身的$ pristine / $ dirty状态。
答案 0 :(得分:3)
我可能会设置元素的value
而不是设置视图值并全部撕掉,因为它只是在手动注册的事件上发生的外观事件,并且您不必使用ngmodel& #39;验证属性。
即:
function _onBlur () {
//....
$element.val(_formatCurrency(ctrl.$modelValue));
}
function _onFocus () {
//...
$element.val(String(ctrl.$modelValue).replace(/\./, ','));
}
<强> Plnkr 强>