Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 本地存储未定义,即使已设置。离子的_Javascript_Angularjs_Cordova_Ionic Framework - Fatal编程技术网

Javascript 本地存储未定义,即使已设置。离子的

Javascript 本地存储未定义,即使已设置。离子的,javascript,angularjs,cordova,ionic-framework,Javascript,Angularjs,Cordova,Ionic Framework,我是以这个为例,, 我已经在app.js文件中声明了ng存储。以及: app.controller('facebookCtrl', ['$cordovaOauth','$scope','$localStorage',function ($cordovaOauth,$scope,oauthService, $localStorage) { $scope.login = function() { $cordovaOauth.facebook("1234566878",

我是以这个为例,,

我已经在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);
        });
    };



 }]);
我一直在

无法设置未定义的属性“currentUser”

我已经尝试在开始时启动它,
$localStorage.set('currentUser',result.access\u令牌)


仍然不起作用

我用这种方法定义本地存储,它对我来说很有效

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);
        });
    };



}]);

我用这种方法定义了localstorage,它对我很有用

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);
        });
    };



}]);