2015-11-25 84 views
0

在我看來吳單擊角JS不起作用

<button type="button" 
       ng-disabled="isProcessing" 
       ng-click="login.ssoFacebook()" 
       class="button button-primary"> 
       <span class="icon icon-social-facebook"></span> 
       Login Using Facebook 
      </button> 

當我點擊按鈕,Facebook並沒有工作 我控制器

this.ssoFacebook = function(){ 
     // intiate 
     ssoAuth.facebook.initiate() 
     .then(function(customer){ 
      if (!customer) throw 'error system'; 

      authService.setCurrentSession(customer, $scope); 
      $timeout(function() { 
       $scope.$emit(GLOBAL_EVENTS.SYSTEM.ACCOUNT.SESSION.LOGIN_SUCCESS); 
      }, 500); 
      // redirect or something 
      $state.go('products', {}, {reload: true}); 
     }) 
     .catch(function(error){ 
      $scope.$emit(GLOBAL_EVENTS.SYSTEM.ACCOUNT.SESSION.LOGIN_FAILED, error); 
     }); 
    }; 

難道我做錯了什麼?感謝推進

+0

你是什麼意思不工作?請顯示完整控制器的代碼。 – Kamo

+0

你可以發佈一些更多的代碼?包括你的控制器的定義請 – yarons

+0

@Kamo它不顯示彈出Facebook認證,這是我的完整代碼控制器[http://plnkr.co/edit/qMI6v34lDklhQmnKvoDs?p=catalogue] – innonx

回答

1

替換此代碼,

this.ssoFacebook = function(){ 
... 
} 

用,

$scope.login = {}; 
$scope.login.ssoFacebook = function(){ 
.. 
} 

這可能是問題。

+0

哦,它仍然不起作用:( – innonx

+0

@did你調試點擊? –

1

如果你想使用的功能,從控制器,而不是範圍,需要在attribute ng-controller

ng-controller="ControllerName as login" 

及以下你的HTML標記此可以使用

<button type="button" 
      ng-disabled="isProcessing" 
      ng-click="login.ssoFacebook()" 
      class="button button-primary"> 
      <span class="icon icon-social-facebook"></span> 
      Login Using Facebook 
</button> 
+0

這實際上是唯一完整的答案。 – skubski

+0

@skubski,但似乎OP已經使用它和其他地方的錯誤 – Grundy

0

更改您的NG-點擊 ng-click="ssoFacebook()"

並在您的控制器中更改:

$scope.ssoFacebook = function(){ ... }

+0

這仍然不會工作,如果有沒有'ng-controller'屬性的聲明。 – skubski