javascript - 范围更改未反射(reflect)在模式 UI 上

标签 javascript angularjs ng-dialog

我有一个已禁用的按钮,必须在一段时间后启用。

我尝试使用 $timeoutng-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/

相关文章:

javascript - 如何使用纯 JavaScript 切换元素的属性?

javascript - 用 HTML 元素替换文本标记

c# - 无法在更新面板 C# 中显示 Tiny MCE Editor

javascript - Angular ng-table 没有加载数据集?

javascript - AngularJS 不创建新对象

angularjs - 使用 controllerAs 语法时如何设置 NgDialog 的范围属性

html - ngDialog - closeModal 事件 - angularjs

javascript - 如何设计 react 选择组件的箭头样式?

javascript - 当文本区域处于可编辑模式时,如何为文本区域中的每一行添加数字前缀

angularjs - Angular Material 对话框弹出窗口未显示