@@ -27,6 +27,59 @@ import {noop} from './util/noop';
27
27
*
28
28
* @see `ApplicationInitStatus`
29
29
*
30
+ * @usageNotes
31
+ *
32
+ * The following example illustrates how to configure a multi-provider using `APP_INITIALIZER` token
33
+ * and a function returning a promise.
34
+ *
35
+ * ```
36
+ * function initializeApp(): Promise<any> {
37
+ * return new Promise((resolve, reject) => {
38
+ * // Do some asynchronous stuff
39
+ * resolve();
40
+ * });
41
+ * }
42
+ *
43
+ * @NgModule ({
44
+ * imports: [BrowserModule],
45
+ * declarations: [AppComponent],
46
+ * bootstrap: [AppComponent],
47
+ * providers: [{
48
+ * provide: APP_INITIALIZER,
49
+ * useFactory: () => initializeApp,
50
+ * multi: true
51
+ * }]
52
+ * })
53
+ * export class AppModule {}
54
+ * ```
55
+ *
56
+ * It's also possible to configure a multi-provider using `APP_INITIALIZER` token and a function
57
+ * returning an observable, see an example below. Note: the `HttpClient` in this example is used for
58
+ * demo purposes to illustrate how the factory function can work with other providers available
59
+ * through DI.
60
+ *
61
+ * ```
62
+ * function initializeApp(httpClient: HttpClient): Observable<any> {
63
+ * return httpClient.get("https://someUrl.com/api/user")
64
+ * .pipe(
65
+ * tap(user => { ... })
66
+ * )
67
+ * }
68
+ *
69
+ * @NgModule ({
70
+ * imports: [BrowserModule, HttpClientModule],
71
+ * declarations: [AppComponent],
72
+ * bootstrap: [AppComponent],
73
+ * providers: [{
74
+ * provide: APP_INITIALIZER,
75
+ * useFactory: initializeApp,
76
+ * deps: [HttpClient],
77
+ * multi: true
78
+ * }]
79
+ * })
80
+ * export class AppModule {}
81
+ * ```
82
+ *
30
83
* @publicApi
31
84
*/
32
85
export const APP_INITIALIZER =
0 commit comments