2017-03-16 10 views
0

我有以下按鈕:NG-禁用,但是當我改變值不刷新

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

例如,當我按下按鈕,谷歌它這樣做:

$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

附上'$ scope.signing = FALSE;'一個'$範圍內$ apply'塊。這可能會解決問題 – surajck

+0

如果您使用'$ scope.signing = {「result」:false}'並將您的按鈕更改爲'ng-disabled =「signing.result」'應該有效。基本上,使用原始數據(布爾,數字,字符串)而不是複雜類型(數組,對象)會給出意想不到的結果。 – grimmdude

+0

非常感謝surajck,增加了$ apply,確實讓它工作 –

回答

0

感謝Surajck,我做了它的工作,將其設置裏面$應用,就像這樣:

$scope.$apply(function() { 
     $scope.signing = false; 
    }); 
相關問題