AngularJS cacheFactory无法正常工作

时间:2015-07-16 21:20:13

标签: angularjs

这是我的代码:

App.directive('topNav', function(API, $cacheFactory) {
    return {
        scope: {},
        restrict: 'E',
        templateUrl: 'packages/partials/includes/header.html',
        link: function($scope) {
            var cache = $cacheFactory('dataCache');

            if( cache !== undefined ) {
                API.data().success(function(data){
                    $scope.phone = data.phone;
                    $scope.mail = data.email;
                    cache.put('data', data);
                 });
            } else {
                $scope.phone = cache.get('data').phone;
                $scope.mail = cache.get('data').email;
                console.log(cache.get('data'));
            }
        }
    };
});

问题是它总是返回undefined,我真的不知道出了什么问题,可能出现什么问题?

0 个答案:

没有答案