/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/examples/injection-token/src/main.ts
33 строки
909 B
Matthieu Riegler
docs(docs-infra): remove unused examples
27 янв 2026, 02:19
27 янв 2026, 02:19
899df39
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ /* eslint-disable @angular-eslint/no-output-native */ // #docregion import {Injector, InjectionToken} from '@angular/core'; interface MyInterface { someProperty: string; } // #docregion InjectionToken const TOKEN = new InjectionToken<MyInterface>('SomeToken'); // Setting up the provider using the same token instance const providers = [ {provide: TOKEN, useValue: {someProperty: 'exampleValue'}}, // Mock value for MyInterface ]; // Creating the injector with the provider const injector = Injector.create({providers}); // Retrieving the value using the same token instance const myInterface = injector.get(TOKEN); // myInterface is inferred to be MyInterface. // #enddocregion InjectionToken