diff --git a/modules/@angular/examples/core/di/ts/contentChildren/content_children_example.ts b/modules/@angular/examples/core/di/ts/contentChildren/content_children_example.ts new file mode 100644 index 0000000000..8e946284c0 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChildren/content_children_example.ts @@ -0,0 +1,46 @@ +/** + * @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, ContentChildren, Directive, Input, QueryList} from '@angular/core'; + +@Directive({selector: 'pane'}) +export class Pane { + @Input() id: string; +} + +@Component({ + selector: 'tab', + template: ` +
panes: {{serializedPanes}}
+ ` +}) +export class Tab { + @ContentChildren(Pane) panes: QueryList; + + get serializedPanes(): string { return this.panes ? this.panes.map(p => p.id).join(', ') : ''; } +} + +@Component({ + selector: 'example-app', + template: ` + + + + + + + + `, +}) +export class ContentChildrenComp { + shouldShow = false; + + show() { this.shouldShow = true; } +} +// #enddocregion diff --git a/modules/@angular/examples/core/di/ts/contentChildren/e2e_test/content_children_spec.ts b/modules/@angular/examples/core/di/ts/contentChildren/e2e_test/content_children_spec.ts new file mode 100644 index 0000000000..663d3f3631 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChildren/e2e_test/content_children_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('contentChildren example', () => { + afterEach(verifyNoBrowserErrors); + let button: ElementFinder; + let result: ElementFinder; + + beforeEach(() => { + browser.get('/core/di/ts/contentChildren/index.html'); + button = element(by.css('button')); + result = element(by.css('div')); + }); + + it('should query content children', () => { + expect(result.getText()).toEqual('panes: 1, 2'); + + button.click(); + + expect(result.getText()).toEqual('panes: 1, 2, 3'); + }); +}); diff --git a/modules/@angular/examples/core/di/ts/contentChildren/module.ts b/modules/@angular/examples/core/di/ts/contentChildren/module.ts new file mode 100644 index 0000000000..18e50ea60c --- /dev/null +++ b/modules/@angular/examples/core/di/ts/contentChildren/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 {ContentChildrenComp, Pane, Tab} from './content_children_example'; + +@NgModule({ + imports: [BrowserModule], + declarations: [ContentChildrenComp, Pane, Tab], + bootstrap: [ContentChildrenComp] +}) +export class AppModule { +}