mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs: complete the example in use InjectionToken section (#57839)
PR Close #57839
This commit is contained in:
parent
7b13d34a24
commit
490786af10
1 changed files with 8 additions and 0 deletions
|
|
@ -161,6 +161,10 @@ The following example defines a token, `APP_CONFIG`. of the type `InjectionToken
|
|||
<docs-code header="src/app/app.config.ts" language="typescript" highlight="[3]">
|
||||
import { InjectionToken } from '@angular/core';
|
||||
|
||||
export interface AppConfig {
|
||||
title: string;
|
||||
}
|
||||
|
||||
export const APP_CONFIG = new InjectionToken<AppConfig>('app.config description');
|
||||
</docs-code>
|
||||
|
||||
|
|
@ -169,6 +173,10 @@ The optional type parameter, `<AppConfig>`, and the token description, `app.conf
|
|||
Next, register the dependency provider in the component using the `InjectionToken` object of `APP_CONFIG`:
|
||||
|
||||
<docs-code header="src/app/app.component.ts" language="typescript">
|
||||
const MY_APP_CONFIG_VARIABLE: AppConfig = {
|
||||
title: 'Hello',
|
||||
};
|
||||
|
||||
providers: [{ provide: APP_CONFIG, useValue: MY_APP_CONFIG_VARIABLE }]
|
||||
</docs-code>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue