简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM