fix(compiler): codegen view query generic types
This commit is contained in:
parent
41ef4b3d4a
commit
e157a065b0
15
modules/@angular/compiler-cli/integrationtest/src/queries.ts
Normal file
15
modules/@angular/compiler-cli/integrationtest/src/queries.ts
Normal file
@ -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: '<comp-for-child-query></comp-for-child-query>',
|
||||||
|
directives: [CompForChildQuery]
|
||||||
|
})
|
||||||
|
export class CompWithChildQuery {
|
||||||
|
@ViewChild(CompForChildQuery) child: CompForChildQuery;
|
||||||
|
@ViewChildren(CompForChildQuery) children: QueryList<CompForChildQuery>;
|
||||||
|
}
|
@ -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 = <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 = <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);
|
||||||
|
});
|
||||||
|
});
|
@ -106,11 +106,13 @@ function mapNestedViews(
|
|||||||
export function createQueryList(
|
export function createQueryList(
|
||||||
query: CompileQueryMetadata, directiveInstance: o.Expression, propertyName: string,
|
query: CompileQueryMetadata, directiveInstance: o.Expression, propertyName: string,
|
||||||
compileView: CompileView): o.Expression {
|
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);
|
var expr = o.THIS_EXPR.prop(propertyName);
|
||||||
compileView.createMethod.addStmt(o.THIS_EXPR.prop(propertyName)
|
compileView.createMethod.addStmt(
|
||||||
.set(o.importExpr(Identifiers.QueryList).instantiate([]))
|
o.THIS_EXPR.prop(propertyName)
|
||||||
.toStmt());
|
.set(o.importExpr(Identifiers.QueryList, [o.DYNAMIC_TYPE]).instantiate([]))
|
||||||
|
.toStmt());
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,15 +70,11 @@ export class QueryList<T> {
|
|||||||
|
|
||||||
toString(): string { return this._results.toString(); }
|
toString(): string { return this._results.toString(); }
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
reset(res: Array<T|any[]>): void {
|
reset(res: Array<T|any[]>): void {
|
||||||
this._results = ListWrapper.flatten(res);
|
this._results = ListWrapper.flatten(res);
|
||||||
this._dirty = false;
|
this._dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
|
||||||
notifyOnChanges(): void { this._emitter.emit(this); }
|
notifyOnChanges(): void { this._emitter.emit(this); }
|
||||||
|
|
||||||
/** internal */
|
/** internal */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user