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?