【问题标题】:Unknown provider in angularJS with angular-cached-resourceangularJS 中的未知提供者与 angular-cached-resource
【发布时间】:2014-08-04 14:53:27
【问题描述】:

我已在我的 Angular 应用程序中正确添加了 Angular-cached-resource (https://github.com/goodeggs/angular-cached-resource) 的 JS 文件,并正在尝试对其进行实例化:

angular.module('client.core.resources')
.factory('TranslationResource', ['$cachedResource', 'ConstantValueService', function ($cachedResource, ConstantValueService) {
    var localizationUrl = ConstantValueService.get('webApiUri') + '/api/localization/';


    // TODO adjust webapi to work.
    return $cachedResource('translationResource', localizationUrl, {lang: '@lang'},
        {
            getTranslationForCulture: {
                method: 'GET',
                isArray: true
            },

        });
}]);

但我收到错误:

[$injector:unpr] 未知提供者:$cachedResourceProvider

我可能做错了什么?

【问题讨论】:

  • 您是否在 HTML 中包含了 angular-cached-resource.js 文件?
  • 你能设置一个 plunker...
  • 您是否在 rmodule 声明中包含了 ngCachedResource 作为依赖项?
  • 是的,@PSL 的建议是完全正确的。 Doc错过了那部分。 PSL,你能回答我吗?
  • @AskarIbragimov 当然添加为答案。

标签: javascript angularjs


【解决方案1】:

$cachedResource 服务是ngCachedResource 模块的一部分,因此为了使用它,您需要将ngCachedResource 列为您应用中的依赖项。

 angular.module('myApp',[...,'ngCachedResource'])....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多