angular js unknown provider

Solution 1:

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

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/

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.

Solution 2:

I got that error because I was passing an incorrect parameter to the factory definition. I had:

myModule.factory('myService', function($scope, $http)...

It worked when I removed the $scope and changed the factory definition to:

myModule.factory('myService', function( $http)...

In case you need to inject $scope, use:

myModule.factory('myService', function($rootScope, $http)...

Solution 3:

I just had a similar problem. The error said the same the in the question, tried to solve it with the answer of pkozlowski.opensource and Ben G, which both are correct and good answers.

My problem was indeed different with the same error:

in my HTML-Code I had the initialisation like this...

<html ng-app>

A bit further down I tried to do something like this:

<div id="cartView" ng-app="myApp" ng-controller="CartCtrl">

I got rid of the first one... then it worked... obviously you can't initialise ng-app twice or more times. fair enough.

I totaly forgot about the first "ng-app" and got totaly frustrated. Maybe this is gonna help someone oneday...

Solution 4:

Make sure your main app.js includes the services on which it depends. For example:

/* App Module */
angular.module('myApp', ['productServices']). 
.....

Solution 5:

pkozlowski's answer is correct, but just in case this happens to someone else, I had the same error after creating the same module twice by mistake; the second definition was overriding the provider of the first:

I created the module by doing

angular.module('MyService'...
).factory(...);

then a bit further down in the same file:

angular.module('MyService'...
).value('version','0.1');

The correct way of doing this is:

angular.module('MyService'...
).factory(...).value('version','0.1');