角JS未知提供商 [英] angular js unknown provider

查看:130
本文介绍了角JS未知提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定制的mongolab例如适合我自己的REST API。现在我遇到了这个错误,我不知道我在做什么错了:

I'm trying to "customize" the mongolab example to fit my own REST API. Now I'm running into this error and I am not sure what I am doing wrong:

Error: Unknown provider: ProductProvider <- Product
    at Error (unknown source)
    at http://localhost:3000/js/vendor/angular.min.js:28:395
    at Object.c [as get] (http://localhost:3000/js/vendor/angular.min.js:26:180)
    at http://localhost:3000/js/vendor/angular.min.js:28:476
    at c (http://localhost:3000/js/vendor/angular.min.js:26:180)
    at d (http://localhost:3000/js/vendor/angular.min.js:26:314)

这是我的控制器:

function ProductListCtrl($scope, Product) {
  $scope.products = Product.query();
}

和这是模块

angular.module('productServices', ['ngResource']).
    factory('Product', ['$resource', function($resource){
      var Product = $resource('/api/products/:id', {  }, {
        update: { method: 'PUT' }
      });

      return Product;
    }]);

有人可以给我一个提示对我缺少什么吗?

can someone give me a hint on what I'm missing?

非常感谢

推荐答案

您code看起来不错,其实它的工作原理(除了电话本身)复制和放大器时;粘贴到一个样品的jsfiddle: http://jsfiddle.net/VGaWD/

Your code looks good, in fact it works (apart from the calls themselves) when copied & pasted into a sample jsFiddle: http://jsfiddle.net/VGaWD/

很难说是怎么回事,没有看到一个更完整的例子,但我希望以上的jsfiddle会有所帮助。 什么,我怀疑的是,你不与'productServices模块初始化您应用。这将给予同样的错误,我们可以在其他的jsfiddle看到这一点: http://jsfiddle.net/a69nX/1/

Hard to say what is going on without seeing a more complete example but I hope that the above jsFiddle will be helpful. What I'm suspecting is that you are not initializing your app with the 'productServices' module. It would give the same error, we can see this in another jsFiddle: http://jsfiddle.net/a69nX/1/

如果您计划使用AngularJS和MongoLab的我会建议使用现有的适配器为$资源和MongoLab 以工作:<一href=\"https://github.com/pkozlowski-opensource/angularjs-mongolab\">https://github.com/pkozlowski-opensource/angularjs-mongolab
它简化了大部分的疼痛MongoLab工作的,你可以看到它在这里的行动:<一href=\"http://jsfiddle.net/pkozlowski_opensource/DP4Rh/\">http://jsfiddle.net/pkozlowski_opensource/DP4Rh/
免责声明!我维持这种适配器(基于AngularJS的例子写的),所以我在这里很明显偏向。

If you are planning to work with AngularJS and MongoLab I would suggest using an existing adapter for the $resource and MongoLab: https://github.com/pkozlowski-opensource/angularjs-mongolab It eases much of the pain working with MongoLab, you can see it in action here: http://jsfiddle.net/pkozlowski_opensource/DP4Rh/ Disclaimer! I'm maintaining this adapter (written based on AngularJS examples) so I'm obviously biased here.

这篇关于角JS未知提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆