0

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:

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?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
snowfinch27
  • 149
  • 2
  • 16

1 Answers1

0

You must change scope to $scope

Bünyamin Sarıgül
  • 3,031
  • 4
  • 30
  • 55
  • Depending on how `$scope` is injected, it may not be necessary. Eg when using the array syntax you can do `['$scope', function(scope){}]` – Aron Aug 15 '16 at 10:08