0

模型更改时,我的角度视图没有更新。模型在指令中的“onblur”事件中发生变化。

inputNgEl.bind('blur', function () { })

我的模型被传递给指令,指令显示模型的内容。

请在下面找到plunk。 http://plnkr.co/edit/Ku5yOyWsa1fjnLIs2Eu3?p=preview

你能告诉我这里缺少什么吗?谢谢。

4

2 回答 2

0

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();
    //});
});
于 2015-02-23T10:19:30.290 回答
0

以下更改对我有用。

inputNgEl.bind('blur', function () { $timeout(function () { scope.$apply(ValidateControl); }, 0, false); });

更正了http://plnkr.co/edit/kSnZbgY5AiaSfQxjbQke?p=preview

于 2015-02-23T14:15:48.030 回答