【问题标题】:ng-disabled on buttons, but it doesn't refresh when I change valueng-disabled 在按钮上,但是当我更改值时它不会刷新
【发布时间】:2017-08-07 19:09:10
【问题描述】:

我有以下按钮:

    <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 知道以某种方式刷新按钮的状态?

【问题讨论】:

  • $scope.signing = false; 括在$scope.$apply 块内。这可能会解决问题
  • 如果您使用 $scope.signing = {"result":false} 并将您的按钮更改为 ng-disabled="signing.result" 应该可以工作。基本上,按原样使用原语(布尔、数字、字符串)而不是复杂类型(数组、对象)会产生意想不到的结果。
  • 非常感谢 surajck,添加了 $apply,确实可以正常工作

标签: javascript jquery angularjs button disabled-input


【解决方案1】:

感谢 Surajck,我成功了,将它设置在 $apply 中,就像这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2015-02-10
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多