我正在使用离子框架创建移动应用,因为我将实现Facebook登录。
我的fblogin()
函数应该在ng-click
上调用,但它没有。任何帮助将不胜感激
<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 :(得分:2)
在离子游戏中添加。它的工作,请点击这里。
答案 1 :(得分:0)
在ion-view
替换 TheNameOFController 中添加此项,并使用您正在使用的控制器的名称
ng-controller="TheNameOFController as ctrl"
这是你的ng-click
ng-click="ctrl.facebookSignIn()"
答案 2 :(得分:0)
我找到了解决方案
$scope.$on('$stateChangeSuccess', function() {
$('*[ng-click]').each(function() {
$(this).attr("ng-click");
$(this).attr("on-touch", $(this).attr("ng-click"));
});
});