gpt4 book ai didi

javascript - AngularJS - 如何在指令中取消同步 $viewValue 和 $modelValue

转载 作者:行者123 更新时间:2023-12-03 05:38:20 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com