我尝试在某些异步通话正在进行时尝试禁用提交按钮,但看起来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;
};
由于某些原因,scope.changeFormProgress = true;
之后似乎没有调用$ digest,但如果我尝试使用scope.$digest();
手动添加它,则会收到错误Error: [$rootScope:inprog] $apply already in progress
。那么,有没有办法让ng-disabled监视这种情况下的价值变化呢?
答案 0 :(得分:0)
您必须将scope
更改为$scope