更改范围不反映模态UI

时间:2016-09-02 13:47:31

标签: 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值,但只有在我关闭并重新打开模式时才会刷新按钮状态。

2 个答案:

答案 0 :(得分:1)

$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)

});

答案 1 :(得分:0)

原来是一个多余的ng-controller。删除其中一个就可以了。