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

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

每当我尝试 运行 这个 plunkr 代码时,它都会抛出错误(请参阅控制台日志)。

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

我想在这里设置 $httpProvider.defaults.cache 默认容量。

首先,您没有将 $cacheFactory 注入您的配置,这就是您获得 'undefined' 的原因。但是,如果您确实将其注入到您的配置中,您的错误将更改为 'Unknown Provider'。这是因为 angular 的配置部分将只接受注入的提供者。

从这里开始: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
});