2016-08-30 9 views
0

https://www.thepolyglotdeveloper.com/2015/02/make-facebook-mobile-app-ionic-framework/ローカルストレージは設定されていても定義されていません。私はこの例を以下の午前イオン

私はapp.jsファイルにNG-ストレージを宣言しました。そして:

app.controller('facebookCtrl', ['$cordovaOauth','$scope','$localStorage',function ($cordovaOauth,$scope,oauthService, $localStorage) 
{ 
$scope.login = function() 
    { 
     $cordovaOauth.facebook("1234566878", ["email", "user_location","public_profile"]).then(function(result) { 
      $localStorage.currentUser = result.access_token; 

      $http.defaults.headers.common.Authorization = 'Bearer ' + $localStorage.currentUser ; 
      console.log ('acess token is ' + result.access_token) 


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



}]); 

私は

が、私はまだ

を動作していない開始と $localStorage.set('currentUser', result.access_token);

でそれを開始しようとしている未定義

のプロパティ 'CurrentUserに' を設定することはできません取得保ちます

答えて

2

私はこの方法でローカルストレージを定義してください。

app.controller('facebookCtrl', ['$cordovaOauth', '$scope', '$localStorage', function($cordovaOauth, $scope, oauthService, $localStorage) { 
    $scope.$storage = $localStorage.$default({ 
     currentUser = null; 
    }); 
    $scope.login = function() { 
     $cordovaOauth.facebook("1234566878", ["email", "user_location", "public_profile"]).then(function(result) { 
      $scope.$storage.currentUser = result.access_token; 

      $http.defaults.headers.common.Authorization = 'Bearer ' + $localStorage.currentUser; 
      console.log('acess token is ' + result.access_token) 


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



}]); 
+0

ありがとう! :)これは働いた – noor

関連する問題