MrPlow
MrPlow

Reputation: 1467

Trying to use $cachefactory throws an [$injector:unpr] error

I'm trying to use $cachefactory in my angular project.

I've created a cache service:

services.js

var AppServices = angular.module('Test.services', [])
.factory('testCache', function($cachefactory){
    return $cachefactory('test');
});

and I'm trying to inject it in my controller like this:

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);
    }  
};

However when I run the application and try to retrieve data I get:

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="">

I've read the error page which claims that I've missed defining a dependency. I'm not sure where I missed it though since app.js injects services module so $cachefactory should be visible, right?

Link to example on plunker

Upvotes: 0

Views: 341

Answers (1)

Chandermani
Chandermani

Reputation: 42669

There is a typo. Use $cacheFactory instead of $cachefactory

Upvotes: 2

Related Questions