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
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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.
Closes#4302
* it('allows events to be tracked', inject(function(tracking) {
302
-
* expect(tracking.event('login')).toEqual(1);
303
-
* expect(tracking.event('login')).toEqual(2);
304
-
* }));
305
-
*
306
-
* it('posts to save', inject(function(tracking) {
307
-
* tracking.save();
308
-
* expect(mocked.post.callCount).toEqual(1);
309
-
* }));
310
-
* });
311
-
* </pre>
312
-
*
313
-
* There are also shorthand methods to define services that don't need to be configured beyond their `$get()` method.
314
-
*
315
-
* `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.
316
-
*
317
-
* <pre>
318
-
* function TrackingProvider($http) {
319
-
* var observed = {};
320
-
* this.event = function(event) {
321
-
* var current = observed[event];
322
-
* return observed[event] = current ? current + 1 : 1;
323
-
* };
324
-
* this.save = function() {
325
-
* $http.post("/track",observed);
326
-
* };
327
-
* }
328
-
* $provider.service('tracking',TrackingProvider);
329
-
* </pre>
330
-
*
331
-
* `factory()` registers a function whose return value is the instance. Again, you can specify services that will be provided by the injector.
332
-
*
333
-
* <pre>
334
-
* function TrackingProvider($http) {
335
-
* var observed = {};
336
-
* return {
337
-
* event: function(event) {
338
-
* var current = observed[event];
339
-
* return observed[event] = current ? current + 1 : 1;
340
-
* },
341
-
* save: function() {
342
-
* $http.post("/track",observed);
343
-
* }
344
-
* };
345
-
* }
346
-
* $provider.factory('tracking',TrackingProvider);
347
-
* </pre>
348
-
*
272
+
* The {@link AUTO.$provide $provide} service has a number of methods for registering components with
273
+
* the {@link AUTO.$injector $injector}. Many of these functions are also exposed on {@link angular.Module}.
274
+
*
275
+
* An Angular **service** is a singleton object created by a **service factory**. These **service
276
+
* factories** are functions which, in turn, are created by a **service provider**.
277
+
* The **service providers** are constructor functions. When instantiated they must contain a property
278
+
* called `$get`, which holds the **service factory** function.
279
+
*
280
+
* When you request a service, the {@link AUTO.$injector $injector} is responsible for finding the
281
+
* correct **service provider**, instantiating it and then calling its `$get` **service factory**
282
+
* function to get the instance of the **service**.
283
+
*
284
+
* Often services have no configuration options and there is no need to add methods to the service
285
+
* provider. The provider will be no more than a constructor function with a `$get` property. For
286
+
* these cases the {@link AUTO.$provide $provide} service has additional helper methods to register
287
+
* services without specifying a provider.
288
+
*
289
+
* * {@link AUTO.$provide#provider provider(provider)} - registers a **service provider** with the
290
+
* {@link AUTO.$injector $injector}
291
+
* * {@link AUTO.$provide#constant constant(obj)} - registers a value/object that can be accessed by
292
+
* providers and services.
293
+
* * {@link AUTO.$provide#value value(obj)} - registers a value/object that can only be accessed by
294
+
* services, not providers.
295
+
* * {@link AUTO.$provide#factory factory(fn)} - registers a service **factory function**, `fn`, that
296
+
* will be wrapped in a **service provider** object, whose `$get` property will contain the given
297
+
* factory function.
298
+
* * {@link AUTO.$provide#service service(class)} - registers a **constructor function**, `class` that
299
+
* will be wrapped in a **service provider** object, whose `$get` property will instantiate a new
300
+
* object using the given constructor function.
301
+
*
302
+
* See the individual methods for more information and examples.
349
303
*/
350
304
351
305
/**
@@ -354,7 +308,18 @@ function annotate(fn) {
354
308
* @methodOf AUTO.$provide
355
309
* @description
356
310
*
357
-
* Register a provider for a service. The providers can be retrieved and can have additional configuration methods.
311
+
* Register a **provider function** with the {@link AUTO.$injector $injector}. Provider functions are
312
+
* constructor functions, whose instances are responsible for "providing" a factory for a service.
313
+
*
314
+
* Service provider names start with the name of the service they provide followed by `Provider`.
315
+
* For example, the {@link ng.$log $log} service has a provider called {@link ng.$logProvider $logProvider}.
316
+
*
317
+
* Service provider objects can have additional methods which allow configuration of the provider and
318
+
* its service. Importantly, you can configure what kind of service is created by the `$get` method,
319
+
* or how that service will act. For example, the {@link ng.$logProvider $logProvider} has a method
0 commit comments