Ng-disabled对价值变化没有反应

时间:2021-08-06 19:42:24

I'm trying to disable submit button while some async call is in progress, but it looks like ng-disabled isn't watching for value change. Here is the code sample:

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

Markup:

<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;
};

It looks like $digest isn't called after scope.changeFormProgress = true; for some reason, but if I try to add it manually with scope.$digest();, I got error Error: [$rootScope:inprog] $apply already in progress. So, is there a way to make ng-disabled watch for value change in this situation?

在scope.changeFormProgress = true之后看起来不会调用$ digest;出于某种原因,但如果我尝试用范围手动添加它。$ digest();,我收到错误错误:[$ rootScope:inprog] $ apply已在进行中。那么,有没有办法让ng-disabled监视这种情况下的价值变化呢?

1 个解决方案

#1


0  

You must change scope to $scope

您必须将范围更改为$ scope

#1


0  

You must change scope to $scope

您必须将范围更改为$ scope