模型更改时,我的角度视图没有更新。模型在指令中的“onblur”事件中发生变化。
inputNgEl.bind('blur', function () {
})
我的模型被传递给指令,指令显示模型的内容。
请在下面找到plunk。 http://plnkr.co/edit/Ku5yOyWsa1fjnLIs2Eu3?p=preview
你能告诉我这里缺少什么吗?谢谢。
模型更改时,我的角度视图没有更新。模型在指令中的“onblur”事件中发生变化。
inputNgEl.bind('blur', function () {
})
我的模型被传递给指令,指令显示模型的内容。
请在下面找到plunk。 http://plnkr.co/edit/Ku5yOyWsa1fjnLIs2Eu3?p=preview
你能告诉我这里缺少什么吗?谢谢。
Angular 不知道您的模型更改:您需要使用scope.$apply()触发摘要
// only apply the has-error class after the user leaves the text box
inputNgEl.bind('blur', function () {
//el.toggleClass('has-error', formCtrl[inputName].$invalid);
//helpText.toggleClass('hide', formCtrl[inputName].$valid);
scope.$apply(ValidateControl);
// Or
//scope.$apply(function () {
// ValidateControl();
//});
});
以下更改对我有用。
inputNgEl.bind('blur', function () {
$timeout(function () {
scope.$apply(ValidateControl);
}, 0, false);
});