$provide
- - service in module auto
angular.Module.An Angular service is a singleton object created by a service factory. These service factories are functions which, in turn, are created by a service provider. The service providers are constructor functions. When instantiated they must contain a property called
$get, which holds the service factory function.When you request a service, the $injector is responsible for finding the correct service provider, instantiating it and then calling its
$get service factory
function to get the instance of the service.Often services have no configuration options and there is no need to add methods to the service provider. The provider will be no more than a constructor function with a
$get property. For
these cases the $provide service has additional helper methods to register
services without specifying a provider.- provider(provider) - registers a service provider with the $injector
- constant(obj) - registers a value/object that can be accessed by providers and services.
- value(obj) - registers a value/object that can only be accessed by services, not providers.
- factory(fn) - registers a service factory function,
fn, that will be wrapped in a service provider object, whose$getproperty will contain the given factory function. - service(class) - registers a constructor function,
classthat will be wrapped in a service provider object, whose$getproperty will instantiate a new object using the given constructor function
No comments:
Post a Comment