0

我正在尝试在一些异步调用正在进行时禁用提交按钮,但它看起来ng-disabled并没有关注值的变化。这是代码示例:

标记:

<button ng-show="!resetSuccess" class="form-input login-button" ng-disabled="changeFormError || changeFormProgress", ng-click="resetPassword(changeForm)">Send Email</button>

JS:

scope.resetPassword = function (form) {
    if (form.$valid) {
        scope.changeFormProgress = true; // value is changed, but ng-disable doesn't react on it
        // scope.$digest(); produces an error
        someAsyncCallReturningPromise.then(function () {
            scope.changeFormProgress = false;
            scope.changeForm.$setPristine();
        }, function (err) {
            scope.changeFormProgress = false;
            scope.changeFormError = true; // changeFormError works ok, ng-disabled watches it
        }); 
    scope.changeFormError = true;
};

看起来 $digestscope.changeFormProgress = true;由于某种原因没有被调用,但是如果我尝试手动添加它scope.$digest();,我得到了 error Error: [$rootScope:inprog] $apply already in progress。那么,有没有办法让 ng-disabled 在这种情况下观察价值变化?

4

1 回答 1

0

您必须更改scope$scope

于 2016-08-15T10:00:29.940 回答