From 1e5327872d465e7f6b6aacc580e2a92c19981cc4 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Fri, 27 Jul 2018 09:47:11 -0500 Subject: [PATCH] docs(core): replace ReflectiveInjector example with Static Injector example (#25162) PR Close #25162 --- packages/examples/core/di/ts/injector_spec.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/examples/core/di/ts/injector_spec.ts b/packages/examples/core/di/ts/injector_spec.ts index 7446721ebe..8434c4565b 100644 --- a/packages/examples/core/di/ts/injector_spec.ts +++ b/packages/examples/core/di/ts/injector_spec.ts @@ -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('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`. 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 {