【发布时间】: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