In our previous Article, we discussed about service and Factory. Here is the complete details about Providers.
Provider allows us to create
and inject a service into configuration phase of our application. For example,
If we want to set API key to access the application, we can set the API key via
provider and pass the provider to the application while its in config phase.
Module.config(function
($provide) {
$provide.provider(‘globalSetting,
function() {
this.$get = function {
var appname = “My 1st
Application”;
return {
appName: appname
};
}
})
});
1.
Inject
$provide built-in service in config method.
2.
Create
a provider service by using $provide.
3.
The
Provider service function has 2 parameters
i. The
provider service Name.
ii. Function
4.
The
provider must have this.$get function
5.
Return the object literal from this function
Now the “globalSetting”
provider is available for all other components. Because it has some properties
and methods in a object.
To View about the Complete Article, Please visit our Main Blog.