javascriptangularjscachefactory

Why am I getting "ReferenceError: $cacheFactory is not defined"


When ever I try to run this plunkr code it throws error (see console log).

http://plnkr.co/edit/I0FsK2S30gfNUhlkKwcB?p=preview

I am trying to set $httpProvider.defaults.cache here with a default capacity.


Solution

  • Firstly you are not injecting $cacheFactory into your config, that is why you are getting 'undefined'. However if you do inject it into your config, your error will change to 'Unknown Provider'. This is because the config section of angular will only accept injected providers.

    From here: https://docs.angularjs.org/guide/module

    angular.module('myModule', []).
    config(function(injectables) { // provider-injector
        // This is an example of config block.
        // You can have as many of these as you want.
        // You can only inject Providers (not instances)
        // into config blocks.
    }).
    run(function(injectables) { // instance-injector
        // This is an example of a run block.
        // You can have as many of these as you want.
        // You can only inject instances (not Providers)
        // into run blocks
    });