我正在使用 Angular JS 1.5.6,我想以编程方式取消同步 $viewValue 和 $modelValue,我希望 $viewValue 保持其当前值,但将 $modelValue 设置为未定义。我尝试了 modelCtrl.$modelValue = undefined
但它不起作用。
这是我的指令的代码
function blurFocusDirective() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, modelCtrl) {
elm.on('blur', function() {
console.log('capture blur event');
modelCtrl.$modelValue = undefined;
});
}
};}
我有plunkered我的问题。
最佳答案
通过用 ngModel.$setViewValue(undefined); 替换
modelCtrl.$modelValue = undefined;
进行修复
关于javascript - AngularJS - 如何在指令中取消同步 $viewValue 和 $modelValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40652932/