Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify querying all descendants #15400

Merged
merged 1 commit into from Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,13 +17,20 @@ export class Pane {
@Component({
selector: 'tab',
template: `
<div>panes: {{serializedPanes}}</div>
<div class="top-level">Top level panes: {{serializedPanes}}</div>
<div class="nested">Arbitrary nested panes: {{serializedNestedPanes}}</div>
`
})
export class Tab {
@ContentChildren(Pane) panes: QueryList<Pane>;
@ContentChildren(Pane) topLevelPanes: QueryList<Pane>;
@ContentChildren(Pane, {descendants: true}) arbitraryNestedPanes: QueryList<Pane>;

get serializedPanes(): string { return this.panes ? this.panes.map(p => p.id).join(', ') : ''; }
get serializedPanes(): string {
return this.topLevelPanes ? this.topLevelPanes.map(p => p.id).join(', ') : '';
}
get serializedNestedPanes(): string {
return this.arbitraryNestedPanes ? this.arbitraryNestedPanes.map(p => p.id).join(', ') : '';
}
}

@Component({
Expand All @@ -32,7 +39,12 @@ export class Tab {
<tab>
<pane id="1"></pane>
<pane id="2"></pane>
<pane id="3" *ngIf="shouldShow"></pane>
<pane id="3" *ngIf="shouldShow">
<tab>
<pane id="3_1"></pane>
<pane id="3_2"></pane>
</tab>
</pane>
</tab>

<button (click)="show()">Show 3</button>
Expand Down
Expand Up @@ -12,19 +12,29 @@ import {verifyNoBrowserErrors} from '../../../../../_common/e2e_util';
describe('contentChildren example', () => {
afterEach(verifyNoBrowserErrors);
let button: ElementFinder;
let result: ElementFinder;
let resultTopLevel: ElementFinder;
let resultNested: ElementFinder;

beforeEach(() => {
browser.get('/core/di/ts/contentChildren/index.html');
button = element(by.css('button'));
result = element(by.css('div'));
resultTopLevel = element(by.css('.top-level'));
resultNested = element(by.css('.nested'));
});

it('should query content children', () => {
expect(result.getText()).toEqual('panes: 1, 2');
expect(resultTopLevel.getText()).toEqual('Top level panes: 1, 2');

button.click();

expect(result.getText()).toEqual('panes: 1, 2, 3');
expect(resultTopLevel.getText()).toEqual('Top level panes: 1, 2, 3');
});

it('should query nested content children', () => {
expect(resultNested.getText()).toEqual('Arbitrary nested panes: 1, 2');

button.click();

expect(resultNested.getText()).toEqual('Arbitrary nested panes: 1, 2, 3, 3_1, 3_2');
});
});