diff --git a/modules/@angular/examples/core/di/ts/contentChild/content_child_example.ts b/modules/@angular/examples/core/di/ts/contentChild/content_child_example.ts new file mode 100644 index 0000000000..cde1dfa40f --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChild/content_child_example.ts @@ -0,0 +1,43 @@ +/** + * @license + * Copyright Google Inc. 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.io/license + */ + +// #docregion Component +import {Component, ContentChild, Directive, Input} from '@angular/core'; + +@Directive({selector: 'pane'}) +export class Pane { + @Input() id: string; +} + +@Component({ + selector: 'tab', + template: ` +
pane: {{pane?.id}}
+ ` +}) +export class Tab { + @ContentChild(Pane) pane: Pane; +} + +@Component({ + selector: 'example-app', + template: ` + + + + + + + `, +}) +export class ContentChildComp { + shouldShow = true; + + toggle() { this.shouldShow = !this.shouldShow; } +} +// #enddocregion diff --git a/modules/@angular/examples/core/di/ts/contentChild/e2e_test/content_child_spec.ts b/modules/@angular/examples/core/di/ts/contentChild/e2e_test/content_child_spec.ts new file mode 100644 index 0000000000..119a346ac8 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChild/e2e_test/content_child_spec.ts @@ -0,0 +1,29 @@ +/** + * @license + * Copyright Google Inc. 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.io/license + */ + +import {verifyNoBrowserErrors} from '../../../../../_common/e2e_util'; + +describe('contentChild example', () => { + afterEach(verifyNoBrowserErrors); + let button: ElementFinder; + let result: ElementFinder; + + beforeEach(() => { + browser.get('/core/di/ts/contentChild/index.html'); + button = element(by.css('button')); + result = element(by.css('div')); + }); + + it('should query content child', () => { + expect(result.getText()).toEqual('pane: 1'); + + button.click(); + + expect(result.getText()).toEqual('pane: 2'); + }); +}); diff --git a/modules/@angular/examples/core/di/ts/contentChild/module.ts b/modules/@angular/examples/core/di/ts/contentChild/module.ts new file mode 100644 index 0000000000..d64982d351 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChild/module.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright Google Inc. 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.io/license + */ + +import {NgModule} from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; +import {ContentChildComp, Pane, Tab} from './content_child_example'; + +@NgModule({ + imports: [BrowserModule], + declarations: [ContentChildComp, Pane, Tab], + bootstrap: [ContentChildComp] +}) +export class AppModule { +}