Skip to content

Commit 1d45029

Browse files
committed
fix(query): the view should not be visible to @query.
@ViewQuery is the correct way to query the view template.
1 parent 448ca38 commit 1d45029

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,14 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
658658
}
659659

660660
private _addViewQueries(host: ElementInjector): void {
661-
if (isPresent(host._query0) && host._query0.originator == host)
661+
if (isPresent(host._query0) && host._query0.originator == host &&
662+
host._query0.query.isViewQuery)
662663
this._addViewQuery(host._query0);
663-
if (isPresent(host._query1) && host._query1.originator == host)
664+
if (isPresent(host._query1) && host._query1.originator == host &&
665+
host._query1.query.isViewQuery)
664666
this._addViewQuery(host._query1);
665-
if (isPresent(host._query2) && host._query2.originator == host)
667+
if (isPresent(host._query2) && host._query2.originator == host &&
668+
host._query2.query.isViewQuery)
666669
this._addViewQuery(host._query2);
667670
}
668671

modules/angular2/test/core/compiler/query_integration_spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ class TextDirective {
397397
}
398398

399399
@Component({selector: 'needs-query'})
400-
@View({directives: [NgFor], template: '<div *ng-for="var dir of query">{{dir.text}}|</div>'})
400+
@View({
401+
directives: [NgFor, TextDirective],
402+
template: '<div text="ignoreme"></div><div *ng-for="var dir of query">{{dir.text}}|</div>'
403+
})
401404
@Injectable()
402405
class NeedsQuery {
403406
query: QueryList<TextDirective>;

0 commit comments

Comments
 (0)