为什么我得到" ReferenceError:$ cacheFactory未定义"

时间:2015-09-13 00:23:15

标签: javascript angularjs cachefactory

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

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

我正在尝试使用默认容量设置$httpProvider.defaults.cache

1 个答案:

答案 0 :(得分:0)

首先,您没有将$cacheFactory注入到配置中,这就是为什么您未定义'。但是,如果您将其注入配置,则您的错误将更改为“未知提供商”。这是因为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
});