diff --git a/modules/@angular/examples/core/di/ts/viewChild/e2e_test/view_child_spec.ts b/modules/@angular/examples/core/di/ts/viewChild/e2e_test/view_child_spec.ts new file mode 100644 index 0000000000..bdb9a19369 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/viewChild/e2e_test/view_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('viewChild example', () => { + afterEach(verifyNoBrowserErrors); + let button: ElementFinder; + let result: ElementFinder; + + beforeEach(() => { + browser.get('/core/di/ts/viewChild/index.html'); + button = element(by.css('button')); + result = element(by.css('div')); + }); + + it('should query view child', () => { + expect(result.getText()).toEqual('Selected: 1'); + + button.click(); + + expect(result.getText()).toEqual('Selected: 2'); + }); +}); diff --git a/modules/@angular/examples/core/di/ts/viewChild/module.ts b/modules/@angular/examples/core/di/ts/viewChild/module.ts new file mode 100644 index 0000000000..0ea1c25ec6 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/viewChild/module.ts @@ -0,0 +1,17 @@ +/** + * @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 {Pane, ViewChildComp} from './view_child_example'; + +@NgModule( + {imports: [BrowserModule], declarations: [ViewChildComp, Pane], bootstrap: [ViewChildComp]}) +export class AppModule { +} diff --git a/modules/@angular/examples/core/di/ts/viewChild/view_child_example.ts b/modules/@angular/examples/core/di/ts/viewChild/view_child_example.ts new file mode 100644 index 0000000000..6ed0d10c49 --- /dev/null +++ b/modules/@angular/examples/core/di/ts/viewChild/view_child_example.ts @@ -0,0 +1,37 @@ +/** + * @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 {AfterViewInit, Component, Directive, Input, ViewChild} from '@angular/core'; + +@Directive({selector: 'pane'}) +export class Pane { + @Input() id: string; +} + +@Component({ + selector: 'example-app', + template: ` + + + + + +
Selected: {{selectedPane}}
+ `, +}) +export class ViewChildComp implements AfterViewInit { + @ViewChild(Pane) + set pane(v: Pane) { + setTimeout(() => { this.selectedPane = v.id; }, 0); + } + selectedPane: string = ''; + shouldShow = true; + toggle() { this.shouldShow = !this.shouldShow; } +} +// #enddocregion