docs(core): replace ReflectiveInjector example with Static Injector example (#25162)

PR Close #25162
This commit is contained in:
Brandon Roberts 2018-07-27 09:47:11 -05:00 committed by Igor Minar
parent 367841d237
commit 1e5327872d
1 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {InjectFlags, InjectionToken, Injector, ReflectiveInjector, Type, inject, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
import {InjectFlags, InjectionToken, Injector, Type, inject, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
class MockRootScopeInjector implements Injector {
constructor(readonly parent: Injector) {}
@ -31,7 +31,7 @@ class MockRootScopeInjector implements Injector {
it('works', () => {
// #docregion Injector
const injector: Injector =
ReflectiveInjector.resolveAndCreate([{provide: 'validToken', useValue: 'Value'}]);
Injector.create({providers: [{provide: 'validToken', useValue: 'Value'}]});
expect(injector.get('validToken')).toEqual('Value');
expect(() => injector.get('invalidToken')).toThrowError();
expect(injector.get('invalidToken', 'notFound')).toEqual('notFound');
@ -40,7 +40,7 @@ class MockRootScopeInjector implements Injector {
it('injects injector', () => {
// #docregion injectInjector
const injector = ReflectiveInjector.resolveAndCreate([]);
const injector = Injector.create({providers: []});
expect(injector.get(Injector)).toBe(injector);
// #enddocregion
});
@ -49,7 +49,7 @@ class MockRootScopeInjector implements Injector {
// #docregion InjectionToken
const BASE_URL = new InjectionToken<string>('BaseUrl');
const injector =
ReflectiveInjector.resolveAndCreate([{provide: BASE_URL, useValue: 'http://localhost'}]);
Injector.create({providers: [{provide: BASE_URL, useValue: 'http://localhost'}]});
const url = injector.get(BASE_URL);
// here `url` is inferred to be `string` because `BASE_URL` is `InjectionToken<string>`.
expect(url).toBe('http://localhost');
@ -58,7 +58,8 @@ class MockRootScopeInjector implements Injector {
it('injects a tree-shakeable InjectionToken', () => {
class MyDep {}
const injector = new MockRootScopeInjector(ReflectiveInjector.resolveAndCreate([MyDep]));
const injector =
new MockRootScopeInjector(Injector.create({providers: [{provide: MyDep, deps: []}]}));
// #docregion ShakeableInjectionToken
class MyService {