Repository navigation
feat(query): allow to query for TemplateRef
#3202
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,12 @@ class NeedsQueryByVarBindings { | |
| constructor(@Query("one,two") query: QueryList<any>) { this.query = query; } | ||
| } | ||
|
|
||
| @Injectable() | ||
| class NeedsTemplateRefQuery { | ||
| query: QueryList<TemplateRef>; | ||
| constructor(@Query(TemplateRef) query: QueryList<TemplateRef>) { this.query = query; } | ||
| } | ||
|
|
||
| @Injectable() | ||
| class NeedsElementRef { | ||
| elementRef; | ||
|
|
@@ -1006,6 +1012,16 @@ export function main() { | |
| expectDirectives(inj.get(NeedsQuery).query, CountingDirective, [0]); | ||
| }) | ||
|
|
||
| it('should contain PreBuiltObjects on the same injector', () => { | ||
| var preBuiltObjects = new PreBuiltObjects(null, null, null, new TemplateRef(<any>new DummyElementRef())); | ||
| var inj = injector(ListWrapper.concat([ | ||
| NeedsTemplateRefQuery | ||
| ], extraBindings), null, | ||
| false, preBuiltObjects); | ||
|
|
||
| expect(inj.get(NeedsTemplateRefQuery).query.first).toBe(preBuiltObjects.templateRef); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, add a check for length too. |
||
| }); | ||
|
|
||
| it('should contain multiple directives from the same injector', () => { | ||
| var inj = injector(ListWrapper.concat([ | ||
| NeedsQuery, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,13 @@ import { | |
| it, | ||
| xit, | ||
| TestComponentBuilder, | ||
| asNativeElements | ||
| asNativeElements, | ||
| By | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is |
||
| } from 'angular2/test_lib'; | ||
|
|
||
|
|
||
| import {Injectable, Optional} from 'angular2/di'; | ||
| import {QueryList} from 'angular2/core'; | ||
| import {QueryList, TemplateRef} from 'angular2/core'; | ||
| import {Query, ViewQuery, Component, Directive, View} from 'angular2/annotations'; | ||
|
|
||
| import {NgIf, NgFor} from 'angular2/angular2'; | ||
|
|
@@ -126,6 +127,24 @@ export function main() { | |
| })); | ||
| }); | ||
|
|
||
| describe('query for TemplateRef', () => { | ||
| it('should find TemplateRefs in the light and shadow dom', | ||
| inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | ||
| var template = '<needs-tpl><template var-x="light"></template></needs-tpl>'; | ||
| tcb.overrideTemplate(MyComp, template) | ||
| .createAsync(MyComp) | ||
| .then((view) => { | ||
| view.detectChanges(); | ||
| var needsTpl: NeedsTpl = view.componentViewChildren[0].inject(NeedsTpl); | ||
| expect(needsTpl.query.first.hasLocal('light')).toBe(true); | ||
| expect(needsTpl.viewQuery.first.hasLocal('shadow')).toBe(true); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a check on the list of both to make sure they are equal to 1. |
||
| async.done(); | ||
| }); | ||
| })); | ||
|
|
||
| }); | ||
|
|
||
| describe("onChange", () => { | ||
| it('should notify query on change', | ||
| inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | ||
|
|
@@ -545,6 +564,18 @@ class NeedsViewQueryOrder { | |
| constructor(@ViewQuery(TextDirective) query: QueryList<TextDirective>) { this.query = query; } | ||
| } | ||
|
|
||
| @Component({selector: 'needs-tpl'}) | ||
| @View({template: '<template var-x="shadow"></template>'}) | ||
| class NeedsTpl { | ||
| viewQuery: QueryList<TemplateRef>; | ||
| query: QueryList<TemplateRef>; | ||
| constructor(@ViewQuery(TemplateRef) viewQuery: QueryList<TemplateRef>, | ||
| @Query(TemplateRef) query: QueryList<TemplateRef>) { | ||
| this.viewQuery = viewQuery; | ||
| this.query = query; | ||
| } | ||
| } | ||
|
|
||
| @Component({selector: 'my-comp'}) | ||
| @View({ | ||
| directives: [ | ||
|
|
@@ -558,6 +589,7 @@ class NeedsViewQueryOrder { | |
| NeedsViewQueryIf, | ||
| NeedsViewQueryNestedIf, | ||
| NeedsViewQueryOrder, | ||
| NeedsTpl, | ||
| TextDirective, | ||
| InertDirective, | ||
| NgIf, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to continue past this point. return early.