auto.$provide.provider()

provider(name, provider);

Register a provider function with the $injector. Provider functions are constructor functions, whose instances are responsible for "providing" a factory for a service.

Service provider names start with the name of the service they provide followed by Provider. For example, the $log service has a provider called $logProvider.

Service provider objects can have additional methods which allow configuration of the provider and its service. Importantly, you can configure what kind of service is created by the $get method, or how that service will act. For example, the $logProvider has a method debugEnabled which lets you specify whether the $log service will log debug messages to the console or not.

Parameters

Param Type Details
name string

The name of the instance. NOTE: the provider will be available under name + 'Provider' key.

provider Objectfunction()

If the provider is:

  • Object: then it should have a $get method. The $get method will be invoked using $injector.invoke() when an instance needs to be created.
  • Constructor: a new instance of the provider will be created using $injector.instantiate(), then treated as object.

Returns

Object

registered provider instance

doc_AngularJS
2016-03-29 16:11:04
Comments
Leave a Comment

Please login to continue.