按钮上的ng-disabled,但是当我更改值

时间:2017-03-16 14:30:54

标签: javascript jquery angularjs button disabled-input

我有以下按钮:

    <button id="facebook" type="button" ng-disabled="signing" ng-click="fblogin()">FACEBOOK</button>
    <button id="google" type="button" ng-disabled="signing" ng-click="googleLogin()">GOOGLE</button>

例如,当我按下Google按钮时,它会执行以下操作:

$scope.googleLogin = function() {
    $scope.signing = true;
    document.getElementById('googleAuth').click();
};

我的gapi这样做:

  gapi.load('auth2', function(){
                      // Retrieve the singleton for the GoogleAuth library and set up the client.
                      auth2 = gapi.auth2.init({
                        client_id: 'MY ID',
                        cookiepolicy: 'single_host_origin',
                        scope: 'email',
                        // Request scopes in addition to 'profile' and 'email'
                        //scope: 'additional_scope'
                      });
                      attachSignin(document.getElementById('googleAuth'));
                    });

该按钮被禁用,这很棒,因为我将$scope.signing更改为TRUE。

但是当我回来时,我这样做:$scope.signing = false;并且没有任何变化,按钮保持禁用状态。当我将签名更改为false时,为什么不启用它,我是否需要让html知道某种方式刷新按钮的状态?

1 个答案:

答案 0 :(得分:0)

感谢Surajck,我把它设置为$ apply,就像这样:

$scope.$apply(function () {
        $scope.signing = false;
    });