Providers
A provider is the most sophisticated method of all the providers. It allows you to have a complex creation function and configuration options. A provider is actually a configurable factory.
var app = angular.module('myModule',[]);
app.provider("myProvider", function() {
this.value = "My Value";
this.setValue = function(newValue) {
this.value = newValue;
};
this.$get = function() {
return this.value;
};
});
app.config(function(myProviderProvider) { // ADDED config section
// Note the extra "Provider" suffix
myProviderProvider.setValue("New Value");
});
Services
A service is an injectable constructor. If you want you can specify the dependencies that you need in the function. A service is a singleton and will only be created once by AngularJS.
app.service("myProvider", function() {
this.getValue = function() {
return "My Value";
};
});
Factories
A factory is an injectable function. A factory is a lot like a service in the sense that it is a singleton and dependencies can be specified in the function. The difference between a factory and a service is that a factory injects a plain function so AngularJS will call the function and a service injects a constructor.
app.factory("myProvider", function() {
return "My Value";
});
Value
A value is nothing more than a simple injectable value. The value can be a string, number but also a function.
var app = angular.module('myModule',[]);
app.value("Value1", "First Value");
app.value("Value2", "Second Value");
Constants
A constant can be injected everywhere. The value of a constant can never be changed.
var app = angular.module('myModule',[]);
app.constant("Constant1", "First Constant Value");
app.constant("Constant2", "Second Constant Value");
Video Tutorial
https://www.youtube.com/watch?v=jpT8vn5AhpY