diff --git a/modules/@angular/compiler-cli/integrationtest/src/queries.ts b/modules/@angular/compiler-cli/integrationtest/src/queries.ts new file mode 100644 index 0000000000..218b488878 --- /dev/null +++ b/modules/@angular/compiler-cli/integrationtest/src/queries.ts @@ -0,0 +1,15 @@ +import {Component, QueryList, ViewChild, ViewChildren} from '@angular/core'; + +@Component({selector: 'comp-for-child-query', template: 'child'}) +export class CompForChildQuery { +} + +@Component({ + selector: 'comp-with-child-query', + template: '', + directives: [CompForChildQuery] +}) +export class CompWithChildQuery { + @ViewChild(CompForChildQuery) child: CompForChildQuery; + @ViewChildren(CompForChildQuery) children: QueryList; +} diff --git a/modules/@angular/compiler-cli/integrationtest/test/query_spec.ts b/modules/@angular/compiler-cli/integrationtest/test/query_spec.ts new file mode 100644 index 0000000000..e2152f1aec --- /dev/null +++ b/modules/@angular/compiler-cli/integrationtest/test/query_spec.ts @@ -0,0 +1,34 @@ +import {DebugElement, QueryList, ReflectiveInjector, getDebugNode, lockRunMode} from '@angular/core'; +import {BROWSER_APP_PROVIDERS, By} from '@angular/platform-browser'; +import {serverPlatform} from '@angular/platform-server'; + +import {CompForChildQuery, CompWithChildQuery} from '../src/queries'; +import {CompWithChildQueryNgFactory} from '../src/queries.ngfactory'; + +describe('child queries', () => { + it('should support compiling child queries', () => { + const appInjector = + ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, serverPlatform().injector); + var childQueryComp = CompWithChildQueryNgFactory.create(appInjector); + + var debugElement = getDebugNode(childQueryComp.location.nativeElement); + var compWithChildren = debugElement.query(By.directive(CompWithChildQuery)); + expect(childQueryComp.instance.child).toBeDefined(); + expect(childQueryComp.instance.child instanceof CompForChildQuery).toBe(true); + + }); + + it('should support compiling children queries', () => { + const appInjector = + ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, serverPlatform().injector); + var childQueryComp = CompWithChildQueryNgFactory.create(appInjector); + + var debugElement = getDebugNode(childQueryComp.location.nativeElement); + var compWithChildren = debugElement.query(By.directive(CompWithChildQuery)); + + childQueryComp.changeDetectorRef.detectChanges(); + + expect(childQueryComp.instance.children).toBeDefined(); + expect(childQueryComp.instance.children instanceof QueryList).toBe(true); + }); +}); diff --git a/modules/@angular/compiler/src/view_compiler/compile_query.ts b/modules/@angular/compiler/src/view_compiler/compile_query.ts index 618736ee62..54a3420be0 100644 --- a/modules/@angular/compiler/src/view_compiler/compile_query.ts +++ b/modules/@angular/compiler/src/view_compiler/compile_query.ts @@ -106,11 +106,13 @@ function mapNestedViews( export function createQueryList( query: CompileQueryMetadata, directiveInstance: o.Expression, propertyName: string, compileView: CompileView): o.Expression { - compileView.fields.push(new o.ClassField(propertyName, o.importType(Identifiers.QueryList))); + compileView.fields.push( + new o.ClassField(propertyName, o.importType(Identifiers.QueryList, [o.DYNAMIC_TYPE]))); var expr = o.THIS_EXPR.prop(propertyName); - compileView.createMethod.addStmt(o.THIS_EXPR.prop(propertyName) - .set(o.importExpr(Identifiers.QueryList).instantiate([])) - .toStmt()); + compileView.createMethod.addStmt( + o.THIS_EXPR.prop(propertyName) + .set(o.importExpr(Identifiers.QueryList, [o.DYNAMIC_TYPE]).instantiate([])) + .toStmt()); return expr; } diff --git a/modules/@angular/core/src/linker/query_list.ts b/modules/@angular/core/src/linker/query_list.ts index 1d9506a270..cfdbaf609a 100644 --- a/modules/@angular/core/src/linker/query_list.ts +++ b/modules/@angular/core/src/linker/query_list.ts @@ -70,15 +70,11 @@ export class QueryList { toString(): string { return this._results.toString(); } - /** - * @internal - */ reset(res: Array): void { this._results = ListWrapper.flatten(res); this._dirty = false; } - /** @internal */ notifyOnChanges(): void { this._emitter.emit(this); } /** internal */