Error: [$injector:unpr] Unknown provider

I've set a service using Angular named uIdentity. But, when I try to call it this way:

app.controller('foo', function(uIdentity){});

I get this error message:

Error: [$injector:unpr] Unknown provider: uIdentityProvider <- uIdentity

How do I fix this, please?

Try this

app.controller('foo', ['uIdentity',function(uIdentity){

}]);

or with more items

app.controller('foo', ['$scope','uIdentity',function($scope, uIdentity){

}]);

Basically you are defining the name of the objects as they are defined and they will be mapped in sequence. Another example:-

app.controller('foo', ['$scope','uIdentity',function($x, y){
   //$x is $scope and y is uIdentity

}]);

If you get error in-spite of that you have something wrong in the uIdentity itself.

In general you may want to make it a habit to always use that syntax. It also makes your code resilient from uglification/minification/obfuscation.

Make sure you define the dependencies

app.service('uIdentity', [function(){

}]);

You have to ensure, that your provider is in the same angular.module like your application OR your application depends on the module your provider is located in.

If your uIdentity-provider is part of a module called myIdentityModule e.g. your application needs myIdentityModule as a dependency.

Your code might be sth like

angular.module('app', ['myIdentityModule'])