diff --git a/modules/@angular/core/src/di/metadata.ts b/modules/@angular/core/src/di/metadata.ts index 8dff4459e2..c7073c19c6 100644 --- a/modules/@angular/core/src/di/metadata.ts +++ b/modules/@angular/core/src/di/metadata.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {stringify} from '../facade/lang'; import {makeParamDecorator} from '../util/decorators'; /** @@ -250,8 +249,7 @@ export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf', []); export interface HostDecorator { /** * @whatItDoes Specifies that an injector should retrieve a dependency from any injector until - * reaching the - * host element of the current component. + * reaching the host element of the current component. * @howToUse * ``` * @Injectable() diff --git a/modules/@angular/examples/core/di/ts/metadata_spec.ts b/modules/@angular/examples/core/di/ts/metadata_spec.ts index 1182676a4e..03ae810402 100644 --- a/modules/@angular/examples/core/di/ts/metadata_spec.ts +++ b/modules/@angular/examples/core/di/ts/metadata_spec.ts @@ -7,7 +7,7 @@ */ import {Component, Directive, Host, Inject, Injectable, Optional, ReflectiveInjector, Self, SkipSelf} from '@angular/core'; -import {TestBed} from '@angular/core/testing'; +import {ComponentFixture, TestBed} from '@angular/core/testing'; export function main() { describe('di metadata examples', () => { @@ -140,26 +140,28 @@ export function main() { @Directive({selector: 'child-directive'}) class ChildDirective { + logs: string[] = []; + constructor(@Optional() @Host() os: OtherService, @Optional() @Host() hs: HostService) { - console.log('os is null', os); - console.log('hs is NOT null', hs); + // os is null: true + this.logs.push(`os is null: ${os === null}`); + // hs is an instance of HostService: true + this.logs.push(`hs is an instance of HostService: ${hs instanceof HostService}`); } } @Component({ selector: 'parent-cmp', - providers: [HostService], - template: ` - Dir: - ` + viewProviders: [HostService], + template: '', }) class ParentCmp { } @Component({ selector: 'app', - providers: [OtherService], - template: `Parent: ` + viewProviders: [OtherService], + template: '', }) class App { } @@ -168,7 +170,14 @@ export function main() { TestBed.configureTestingModule({ declarations: [App, ParentCmp, ChildDirective], }); - expect(() => TestBed.createComponent(App)).not.toThrow(); + + let cmp: ComponentFixture; + expect(() => cmp = TestBed.createComponent(App)).not.toThrow(); + + expect(cmp.debugElement.children[0].children[0].injector.get(ChildDirective).logs).toEqual([ + 'os is null: true', + 'hs is an instance of HostService: true', + ]); }); });