我正在尝试在我的角度项目中使用$cachefactory。
我已经创建了缓存服务:
services.js
var AppServices = angular.module('Test.services', [])
.factory('testCache', function($cachefactory){
return $cachefactory('test');
});
我试图将它注入我的控制器中:
TestController.js
var TestController =function($scope, $http, testCache) {
var cache = testCache.get('test');
if(cache) {
$scope.test = cache;
}
else {
var value = "Test Value";
$scope.test = value;
cache.put('test', value);
}
};
然而,当我运行应用程序并尝试检索数据时,我得到:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.17/$injector/unpr?p0=%24cachefactoryProvider%20%3C-%20%24cachefactory%20%3C-%20testCache
u/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:6:443
ec/l.$injector<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:36:139
c@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:34:195
ec/p.$injector<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:36:209
c@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:34:195
d@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:34:409
ec/p.$injector<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:36:222
c@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:34:195
d@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:34:409
f/<.instantiate@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:35:101
Od/this.$get</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:66:463
$ViewDirectiveFill/<.compile/<@https://rawgit.com/angular-ui/ui-router/0.2.10/release/angular-ui-router.js:2797:1
N@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:54:85
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:47:55
v/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:46:253
updateView@https://rawgit.com/angular-ui/ui-router/0.2.10/release/angular-ui-router.js:2733:1
$ViewDirective/directive.compile/</<@https://rawgit.com/angular-ui/ui-router/0.2.10/release/angular-ui-router.js:2697:11
Yd/this.$get</h.prototype.$broadcast@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:113:355
transitionTo/$state.transition<@https://rawgit.com/angular-ui/ui-router/0.2.10/release/angular-ui-router.js:2114:11
ze/e/l.promise.then/D@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:99:243
ze/f/<.then/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:100:407
Yd/this.$get</h.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:110
Yd/this.$get</h.prototype.$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:108:180
Yd/this.$get</h.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:449
e/h<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:122:1
e@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:37:438
se/h.defer/c<@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:41:120
<div class="ng-scope" ui-view="">
我已经阅读了error page,声称我错过了定义依赖项。我不知道我错过了哪里,因为app.js注入服务模块所以$ cachefactory应该是可见的,对吗?
答案 0 :(得分:2)
有一个错字。使用$cacheFactory
代替$cachefactory