2016-06-28 85 views
0

我正在使用離子框架創建移動應用程序,我將實施Facebook登錄。ng-click for ionic ios is not working

我的fblogin()函數應該調用ng-click但它沒有。任何幫助您使用

ng-controller="TheNameOFController as ctrl" 

,這可以理解

<ion-view class="welcome-view" ng-controller="WelcomeCtrl as ctrl" cache-view="false"> 
    <ion-content scroll="false"> 
    <div class="top-content row"> 
     <div class="app-copy col col-top"> 
     <h1 class="app-logo">logo</h1> 
     <p class="app-tagline"> 
      This app helps you discover and buy amazing things all in one place. 
      </p> 
     </div> 
    </div> 
    <div class="bottom-content row"> 
     <div class="col col-bottom"> 
     <a class="facebook-sign-in button button-block" ng-click="facebookSignIn()"> 
      Log in with Facebook 
     </a> 
     </div> 
    </div> 
    </ion-content> 
</ion-view> 

我fblogin功能

.controller('WelcomeCtrl', function($scope, $state, $q, UserService, $ionicLoading) { 

      alert('Facebook login init'); 
//This method is executed when the user press the "Login with facebook" button 
    $scope.facebookSignIn = function() { 

     alert('Facebook login init'); 
    facebookConnectPlugin.getLoginStatus(function(success){ 


    if(success.status === 'connected'){ 
     // the user is logged in and has authenticated your app, and response.authResponse supplies 
     // the user's ID, a valid access token, a signed request, and the time the access token 
     // and signed request each expire 
     console.log('getLoginStatus', success.status); 

       //check if we have our user saved 
       var user = UserService.getUser('facebook'); 

       if(!user.userID) 
       { 
        getFacebookProfileInfo(success.authResponse) 
        .then(function(profileInfo) { 

         //for the purpose of this example I will store user data on local storage 
         UserService.setUser({ 
          authResponse: success.authResponse, 
          userID: profileInfo.id, 
          name: profileInfo.name, 
          email: profileInfo.email, 
          picture : "http://graph.facebook.com/" + success.authResponse.userID + "/picture?type=large" 
         }); 

         $state.go('app.home'); 

        }, function(fail){ 
         //fail get profile info 
         console.log('profile info fail', fail); 
        }); 
       }else{ 
        $state.go('app.home'); 
       } 

    } else { 
     //if (success.status === 'not_authorized') the user is logged in to Facebook, but has not authenticated your app 
     //else The person is not logged into Facebook, so we're not sure if they are logged into this app or not. 
     console.log('getLoginStatus', success.status); 

       $ionicLoading.show({ 
      template: 'Logging in...' 
     }); 

     //ask the permissions you need. You can learn more about FB permissions here: https://developers.facebook.com/docs/facebook-login/permissions/v2.4 
     facebookConnectPlugin.login(['email', 'public_profile'], fbLoginSuccess, fbLoginError); 
     } 
    }); 
    }; 

}) 
+0

一個解決方案可以把你這裏對您的javascript函數()控制器並驗證您的JavaScript代碼是從這個頁面訪問。 – Ali786

+0

alert('Facebook login init');當我的應用加載 –

回答

2

添加在離子游戲中。它的工作,請點擊這裏。

http://play.ionic.io/app/29b9296b6f89

+0

你能檢查我的fblogin函數嗎? –

+0

你有任何角度js錯誤? –

+0

沒有。它沒有顯示任何錯誤日誌 –

0

ion-view更換TheNameOFController與控制器的名稱添加此您的ng-click

ng-click="ctrl.facebookSignIn()" 
+0

時,此警報被調用。但沒有奏效。我已經更新了我的問題 –

0

我發現對於

$scope.$on('$stateChangeSuccess', function() { 

     $('*[ng-click]').each(function() { 
      $(this).attr("ng-click"); 
      $(this).attr("on-touch", $(this).attr("ng-click")); 
     }); 
});