2014-10-31 91 views
1

我正試圖在我的應用中實現角度緩存。我已經下載了它,包括HTML標籤

不過,我不斷收到錯誤:錯誤:[$注射器: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

。服務( '爲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

U忘了包含角緩存模塊依賴關係

+0

感謝您的評論。我宣佈它是這樣的:我的app.js var starter = angular.module('starter',['ionic','starter.services','jmdobry.angular-cache'])但我得到以下錯誤:Uncaught錯誤:[$ injector:modulerr]由於: 錯誤:[$ injector:modulerr]未能實例化模塊啓動器。角度緩存「不可用!您拼錯了模塊名稱或忘記加載模塊名稱。如果註冊模塊確保您指定依賴關係作爲第二個參數。 – Joanna 2014-11-03 12:03:50

+0

哪個版本的angular-cache ru使用 for 2.xx爲3.xx添加'jmdobry.angular-cache' 添加「angular-data.DSCacheFactory」(docs:http://angular-data.pseudobry.com/文檔/ api/angular-cache/angular-cache) – mayank 2014-11-06 14:05:06

+0

嗨,是的,我唱了錯誤的版本,我現在下載了正確的版本,它工作正常 – Joanna 2014-11-06 18:56:42

相關問題