2016-06-28 87 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")); 
     }); 
});