ngModelCtrl - $setViewValue 没有 $setDirty();
ngModelCtrl - $setViewValue without $setDirty();
我有一个指令,它通过模糊时的 ngModelCtrl.$setViewValue() 操作输入字段的 $viewValue。
function _onFocus () {
presentation = false;
if(!ctrl.$isEmpty(ctrl.$modelValue)) {
ctrl.$setViewValue(String(ctrl.$modelValue).replace(/\./, ','));
ctrl.$render();
}
}
由于这只是外观问题,我想知道是否有可能在不改变输入字段本身的 $pristine/$dirty 状态的情况下设置 ViewValue。
参考Angular:$setDirty on $commitViewValue
我可能会设置元素的 value
而不是设置视图值并重新渲染,因为它只是发生在手动注册事件上的外观,你不必玩ngmodel 的验证属性。
即:
function _onBlur () {
//....
$element.val(_formatCurrency(ctrl.$modelValue));
}
function _onFocus () {
//...
$element.val(String(ctrl.$modelValue).replace(/\./, ','));
}
我有一个指令,它通过模糊时的 ngModelCtrl.$setViewValue() 操作输入字段的 $viewValue。
function _onFocus () {
presentation = false;
if(!ctrl.$isEmpty(ctrl.$modelValue)) {
ctrl.$setViewValue(String(ctrl.$modelValue).replace(/\./, ','));
ctrl.$render();
}
}
由于这只是外观问题,我想知道是否有可能在不改变输入字段本身的 $pristine/$dirty 状态的情况下设置 ViewValue。
参考Angular:$setDirty on $commitViewValue
我可能会设置元素的 value
而不是设置视图值并重新渲染,因为它只是发生在手动注册事件上的外观,你不必玩ngmodel 的验证属性。
即:
function _onBlur () {
//....
$element.val(_formatCurrency(ctrl.$modelValue));
}
function _onFocus () {
//...
$element.val(String(ctrl.$modelValue).replace(/\./, ','));
}