未知提供者:$ angularCacheFactoryProvider - 无法找到angular-cache

时间:2014-10-31 17:38:08

标签: caching

我正在尝试在我的应用中实现角度缓存。我已下载并在html中包含标签

但是我一直收到错误:错误:[$ injector:unpr]未知提供者:$ angularCacheFactoryProvider< - $ angularCacheFactory

我很感激一些帮助

我的代码如下:

controllers.js

.controller('PlaylistsCtrl', ['$scope', '$angularCacheFactory', 'myService', '$http', '$rootScope', 'Util', '$location', function ($scope, $angularCacheFactory, myService, $http, $rootScope, Util, $location) {

             $rootScope.allDeals = [];

             $scope.navigate = function(url){
                 $location.path(url);
             };

             myService.getDataById(1)
                 .then(function (data) {
                     // e.g. "time taken for request: 2375ms"
                     // Data returned by this next call is already cached.
                     myService.getDataById(1)
                         .then(function (data) {
                             // e.g. "time taken for request: 1ms"
                         });
                    });

             }])

services.js

.service('myService',['$ http','$ q','$ rootScope','$ angularCacheFactory',函数($ http,$ q,$ rootScope,$ angularCacheFactory){

    $rootScope.allDeals = [];

    $angularCacheFactory('dataCache', {

        maxAge: 900000,

        // Items will be actively deleted when they expire
        deleteOnExpire: 'aggressive',


        // This cache will clear itself every hour
        cacheFlushInterval: 3600000

          });
    return {
        getDataById: function (id) {
            var deferred = $q.defer(),
                start = new Date().getTime();

            $http.get('http://dev.somecompany.net/bigcapi/info/info/someinfo' + id, {
                params: {all: '1', mobileready: 1},
                cache: $angularCacheFactory.get('dataCache')
            }).success(function (data) {
                $rootScope.allDeals = data;
                console.log('time taken for request: ' + (new Date().getTime() - start) + 'ms');
                deferred.resolve(data);
            });
            return deferred.promise;
             }
         };


     }])

1 个答案:

答案 0 :(得分:1)

你忘了包含angular-cache模块依赖