Pages

Thursday, 7 January 2016

$provide service in angular js and there usages along with methods Factory, Service, Provider, Decorator, Value, Constant explanation

In this post we are going to see the $provide service in angular Js, actually what is the $provide service where it is used in angular js, How we can use it in our application$provide is a service which is used register the components with the $injectorBelow statement is a reference from the Angular Website: An angular Service is a singleton object created by a ServiceFactory,ServiceFactory are functions which are created by a ServiceProviderServiceProvider are constructor functions must have $get property which holds the ServiceFactory.so from above statement we came to know that service is created by combination of ServiceFactory, which is holds inside the ServiceProvider $get property.factory(fn) - register a factory function, wrapped in a serviceprovider, $get property contains a fnservice(class) - register a constructor function wrapped in a serviceprovider, $get property instantiate the new objectprovider(provider) - register a service provider with $injectorvalue(obj) - register a name/value, access by service, not providersconstant(obj) - register a name/value, access by service ,providers

Methods Present in the $provide
**************************************

Provider:provider(name,provider)Service provider name starts with the name of the service + 'Provider', like $routeProvider, $logProvider

name = name of the providerprovider = it may be function or object , if it is a function , then it must be a constructor function $injector.instantiate() will be invoked when an instance needs to be createdif it is a object then it must have a $get method, $get will be invoked using $injector.invoke()when an instance needs to be created

Decorator: decorator(name,decorator)This is used to override or modify the service implementation , this is called by $injector.invoke() , it must have one parameter $delegate which the actual implementation of the function, if we want we can use it by executing it.