2015-11-19 66 views
0

我使用本教程https://github.com/nraboy/ng-cordova-facebook-example但該示例不是實現註銷的功能,我添加以下代碼:如何使用cordova ion應用程序註銷Facebook?

facebookExample.controller("LogoutController", function($scope, $http, $localStorage, $location) { 
    $scope.logout = function() { 
    $cordovaFacebook.logout(); 

    }, function(error) { 
     alert("There was a problem signing in! See the console for logs"); 
     console.log(error); 
    } 
}); 

profile.html:

<ion-nav-buttons side="right"> 
    <button class="button icon-left ion-log-out button-stable" ng-controller="LogoutController" ng-click="logout()">Logout</button> 
    </ion-nav-buttons> 

但我發現任何結果

+0

facebook實例?使用你自己的名字應用 –

+0

不是功能:( –

回答

0

你的代碼是無效的JavaScript ......很多解析錯誤。另外,你不需要另外一個控制器來註銷。一個用戶登錄是基於在localStorage的訪問令牌,剛擦它,去到另一個狀態的事實..更新您的個人資料控制器這樣的:

facebookExample.controller("ProfileController", function($scope, $http, $localStorage, $location) { 

    $scope.init = function() { 
     if($localStorage.hasOwnProperty("accessToken") === true) { 
      $http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id,name,gender,location,website,picture,relationship_status", format: "json" }}).then(function(result) { 
       $scope.profileData = result.data; 
      }, function(error) { 
       alert("There was a problem getting your profile. Check the logs for details."); 
       console.log(error); 
      }); 
     } else { 
     alert("Not signed in"); 
     $location.path("/login"); 
     } 
    }; 

    $scope.logout = function(){ 
     delete $localStorage.accessToken; 
     $location.path("/login"); 
    }; 

}); 

profile.html:

<ion-nav-buttons side="right"> 
    <button class="button icon-left ion-log-out button-stable" ng-click="logout()">Logout</button> 
    </ion-nav-buttons> 
+0

非常感謝mani –

相關問題