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;
}
};
}])
感谢您的评论。我宣布它是这样的:我的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
哪个版本的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
嗨,是的,我唱了错误的版本,我现在下载了正确的版本,它工作正常 – Joanna 2014-11-06 18:56:42