You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the "tracking" service example by adding a configuration option.
Get better formatting of the generated code samples using <pre> tags.
Move the detailed explanations into each function's documentation block.
Improve the overview and list the constituent functions by significance.
Closesangular#4302
* it('allows events to be tracked', inject(function(tracking) {
286
-
* expect(tracking.event('login')).toEqual(1);
287
-
* expect(tracking.event('login')).toEqual(2);
288
-
* }));
289
-
*
290
-
* it('posts to save', inject(function(tracking) {
291
-
* tracking.save();
292
-
* expect(mocked.post.callCount).toEqual(1);
293
-
* }));
294
-
* });
295
-
* </pre>
296
-
*
297
-
* There are also shorthand methods to define services that don't need to be configured beyond their `$get()` method.
298
-
*
299
-
* `service()` registers a constructor function which will be invoked with `new` to create the instance. You can specify services that will be provided by the injector.
300
-
*
301
-
* <pre>
302
-
* function TrackingProvider($http) {
303
-
* var observed = {};
304
-
* this.event = function(event) {
305
-
* var current = observed[event];
306
-
* return observed[event] = current ? current + 1 : 1;
307
-
* };
308
-
* this.save = function() {
309
-
* $http.post("/track",observed);
310
-
* };
311
-
* }
312
-
* $provider.service('tracking',TrackingProvider);
313
-
* </pre>
314
-
*
315
-
* `factory()` registers a function whose return value is the instance. Again, you can specify services that will be provided by the injector.
316
-
*
317
-
* <pre>
318
-
* function TrackingProvider($http) {
319
-
* var observed = {};
320
-
* return {
321
-
* event: function(event) {
322
-
* var current = observed[event];
323
-
* return observed[event] = current ? current + 1 : 1;
324
-
* },
325
-
* save: function() {
326
-
* $http.post("/track",observed);
327
-
* }
328
-
* };
329
-
* }
330
-
* $provider.factory('tracking',TrackingProvider);
331
-
* </pre>
332
-
*
256
+
* The {@link AUTO.$provide $provide} service has a number of methods for registering components with
257
+
* the {@link AUTO.$injector $injector}. Many of these functions are also exposed on {@link angular.Module}.
258
+
*
259
+
* An Angular **service** is a singleton object created by a **service factory**. These **service
260
+
* factories** are functions which, in turn, are created by a **service provider**.
261
+
* The **service providers** are constructor functions. When instantiated they must contain a property
262
+
* called `$get`, which holds the **service factory** function.
263
+
*
264
+
* When you request a service, the {@link AUTO.$injector $injector} is responsible for finding the
265
+
* correct **service provider**, instantiating it and then calling its `$get` **service factory**
266
+
* function to get the instance of the **service**.
267
+
*
268
+
* Often services have no configuration options and there is no need to add methods to the service
269
+
* provider. The provider will be no more than a constructor function with a `$get` property. For
270
+
* these cases the {@link AUTO.$provide $provide} service has additional helper methods to register
271
+
* services without specifying a provider.
272
+
*
273
+
* * {@link AUTO.$provide#provider provider(provider)} - registers a **service provider** with the
274
+
* {@link AUTO.$injector $injector}
275
+
* * {@link AUTO.$provide#constant constant(obj)} - registers a value/object that can be accessed by
276
+
* providers and services.
277
+
* * {@link AUTO.$provide#value value(obj)} - registers a value/object that can only be accessed by
278
+
* services, not providers.
279
+
* * {@link AUTO.$provide#factory factory(fn)} - registers a service **factory function**, `fn`, that
280
+
* will be wrapped in a **service provider** object, whose `$get` property will contain the given
281
+
* factory function.
282
+
* * {@link AUTO.$provide#service service(class)} - registers a **constructor function**, `class` that
283
+
* will be wrapped in a **service provider** object, whose `$get` property will instantiate a new
284
+
* object using the given constructor function.
285
+
*
286
+
* See the individual methods for more information and examples.
333
287
*/
334
288
335
289
/**
@@ -338,7 +292,18 @@ function annotate(fn) {
338
292
* @methodOf AUTO.$provide
339
293
* @description
340
294
*
341
-
* Register a provider for a service. The providers can be retrieved and can have additional configuration methods.
295
+
* Register a **provider function** with the {@link AUTO.$injector $injector}. Provider functions are
296
+
* constructor functions, whose instances are responsible for "providing" a factory for a service.
297
+
*
298
+
* Service provider names start with the name of the service they provide followed by `Provider`.
299
+
* For example, the {@link ng.$log $log} service has a provider called {@link ng.$logProvider $logProvider}.
300
+
*
301
+
* Service provider objects can have additional methods which allow configuration of the provider and
302
+
* its service. Importantly, you can configure what kind of service is created by the `$get` method,
303
+
* or how that service will act. For example, the {@link ng.$logProvider $logProvider} has a method
0 commit comments