我有一个已禁用的按钮,必须在一段时间后启用。
我尝试使用 $timeout
和 ng-disabled
来完成此操作,但它不起作用。
HTML:
<button id="resend_button" class="btn btn-block btn-info" ng-click="reenviar_confirmacao()" ng-disabled="!buttonEnabled">{{'RESEND-CONFIRMATION' | translate}}</button>
模态打开:
ngDialog.open({
id: 'confirmation',
template: '../../../templates/confirmacao-sms.html',
preCloseCallback: callback,
backdrop : 'static',
keyboard : false,
scope: $scope
});
功能:
$timeout(function(){
console.log(angular.element("#resend_button"));
// Tried this but didn't work aswell
angular.element("#resend_button").removeAttr('disabled');
$scope.buttonEnabled = true;
$scope.$apply();
}, 2000)
它会更改 $scope.buttonEnblaed
值,但只有在我关闭并重新打开模式时才会刷新按钮状态。
最佳答案
将超时写入$scope.$apply
$scope.$apply(function(){
$timeout(function(){
console.log(angular.element("#resend_button"));
// Tried this but didn't work aswell
angular.element("#resend_button").removeAttr('disabled');
$scope.buttonEnabled = true;
}, 2000)
});
关于javascript - 范围更改未反射(reflect)在模式 UI 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293991/