Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CountdownLocalVarParentComponent { }
})
export class CountdownViewChildParentComponent implements AfterViewInit {

@ViewChild(CountdownTimerComponent)
@ViewChild(CountdownTimerComponent, {static: false})
private timerComponent: CountdownTimerComponent;

seconds() { return 0; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AdComponent } from './ad.component';
export class AdBannerComponent implements OnInit, OnDestroy {
@Input() ads: AdItem[];
currentAdIndex = -1;
@ViewChild(AdDirective) adHost: AdDirective;
@ViewChild(AdDirective, {static: true}) adHost: AdDirective;
interval: any;

constructor(private componentFactoryResolver: ComponentFactoryResolver) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AfterContentComponent implements AfterContentChecked, AfterContentI
comment = '';

// Query for a CONTENT child of type `ChildComponent`
@ContentChild(ChildComponent) contentChild: ChildComponent;
@ContentChild(ChildComponent, {static: false}) contentChild: ChildComponent;

// #enddocregion hooks
constructor(private logger: LoggerService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
private prevHero = '';

// Query for a VIEW child of type `ChildViewComponent`
@ViewChild(ChildViewComponent) viewChild: ChildViewComponent;
@ViewChild(ChildViewComponent, {static: false}) viewChild: ChildViewComponent;

// #enddocregion hooks
constructor(private logger: LoggerService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class DoCheckParentComponent {
hero: Hero;
power: string;
title = 'DoCheck';
@ViewChild(DoCheckComponent) childView: DoCheckComponent;
@ViewChild(DoCheckComponent, {static: false}) childView: DoCheckComponent;

constructor() { this.reset(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class OnChangesParentComponent {
hero: Hero;
power: string;
title = 'OnChanges';
@ViewChild(OnChangesComponent) childView: OnChangesComponent;
@ViewChild(OnChangesComponent, {static: false}) childView: OnChangesComponent;

constructor() {
this.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Hero } from './hero';
})
export class HeroFormComponent {
@Input() hero: Hero;
@ViewChild('heroForm') form: NgForm;
@ViewChild('heroForm', {static: false}) form: NgForm;

private _submitMessage = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Component, AfterViewInit, ViewChild } from '@angular/core';
})
export class CanvasComponent implements AfterViewInit {
blobSize: number;
@ViewChild('sampleCanvas') sampleCanvas;
@ViewChild('sampleCanvas', {static: false}) sampleCanvas;

constructor() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ class HostComponent {
path = 'code-path';
hidecopy: boolean | string = false;

@ViewChild(CodeExampleComponent) codeExampleComponent: CodeExampleComponent;
@ViewChild(CodeExampleComponent, {static: true}) codeExampleComponent: CodeExampleComponent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ describe('CodeTabsComponent', () => {
`
})
class HostComponent {
@ViewChild(CodeTabsComponent) codeTabsComponent: CodeTabsComponent;
@ViewChild(CodeTabsComponent, {static: true}) codeTabsComponent: CodeTabsComponent;
}
2 changes: 1 addition & 1 deletion aio/src/app/custom-elements/code/code.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class HostComponent implements AfterViewInit {
region: string;
header: string;

@ViewChild(CodeComponent) codeComponent: CodeComponent;
@ViewChild(CodeComponent, {static: false}) codeComponent: CodeComponent;

ngAfterViewInit() {
this.setCode(oneLineCode);
Expand Down
2 changes: 1 addition & 1 deletion aio/src/testing/doc-viewer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TestDocViewerComponent extends DocViewerComponent {
})
export class TestParentComponent {
currentDoc?: DocumentContents|null;
@ViewChild(DocViewerComponent) docViewer: DocViewerComponent;
@ViewChild(DocViewerComponent, {static: true}) docViewer: DocViewerComponent;
}

// Mock services.
Expand Down
14 changes: 6 additions & 8 deletions integration/dynamic-compiler/src/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ declare var System: any;
`,
})
export class AppComponent implements AfterViewInit {
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
@ViewChild('vc', {read: ViewContainerRef, static: false}) container: ViewContainerRef;

constructor(private compiler: Compiler) {
}
constructor(private compiler: Compiler) {}

ngAfterViewInit() {
System.import('./dist/lazy.bundle.js').then((module: any) => {
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule)
.then((compiled) => {
const factory = compiled.componentFactories[0];
this.container.createComponent(factory);
});
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule).then((compiled) => {
const factory = compiled.componentFactories[0];
this.container.createComponent(factory);
});
});
}
}
26 changes: 12 additions & 14 deletions packages/common/test/directives/ng_component_outlet_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {NgComponentOutlet} from '@angular/common/src/directives/ng_component_out
import {Compiler, Component, ComponentRef, Inject, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, Optional, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {modifiedInIvy} from '@angular/private/testing';

describe('insert/remove', () => {

Expand Down Expand Up @@ -108,19 +107,18 @@ describe('insert/remove', () => {
}));


modifiedInIvy('Static ViewChild and ContentChild queries are resolved in update mode')
.it('should resolve with an injector', async(() => {
let fixture = TestBed.createComponent(TestComponent);
it('should resolve with an injector', async(() => {
let fixture = TestBed.createComponent(TestComponent);

// We are accessing a ViewChild (ngComponentOutlet) before change detection has run
fixture.componentInstance.cmpRef = null;
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef !;
expect(cmpRef).toBeAnInstanceOf(ComponentRef);
expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent);
expect(cmpRef.instance.testToken).toBeNull();
}));
// We are accessing a ViewChild (ngComponentOutlet) before change detection has run
fixture.componentInstance.cmpRef = null;
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef !;
expect(cmpRef).toBeAnInstanceOf(ComponentRef);
expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent);
expect(cmpRef.instance.testToken).toBeNull();
}));

it('should render projectable nodes, if supplied', async(() => {
const template = `<ng-template>projected foo</ng-template>${TEST_CMP_TEMPLATE}`;
Expand Down Expand Up @@ -240,7 +238,7 @@ class TestComponent {
// TODO(issue/24571): remove '!'.
@ViewChildren(TemplateRef) tplRefs !: QueryList<TemplateRef<any>>;
// TODO(issue/24571): remove '!'.
@ViewChild(NgComponentOutlet) ngComponentOutlet !: NgComponentOutlet;
@ViewChild(NgComponentOutlet, {static: true}) ngComponentOutlet !: NgComponentOutlet;

constructor(public vcRef: ViewContainerRef) {}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/directives/ng_switch_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ class TestComponent {
`
})
class ComplexComponent {
@ViewChild('foo') foo !: TemplateRef<any>;
@ViewChild('bar') bar !: TemplateRef<any>;
@ViewChild('foo', {static: true}) foo !: TemplateRef<any>;
@ViewChild('bar', {static: true}) bar !: TemplateRef<any>;
state: string = 'case1';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/integrationtest/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CompForChildQuery {
@Component(
{selector: 'comp-with-child-query', template: '<comp-for-child-query></comp-for-child-query>'})
export class CompWithChildQuery {
@ViewChild(CompForChildQuery) child: CompForChildQuery;
@ViewChild(CompForChildQuery, {static: true}) child: CompForChildQuery;
@ViewChildren(CompForChildQuery) children: QueryList<CompForChildQuery>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild(SomeDirective) someDir: SomeDirective;
@ContentChild(SomeDirective, {static: false}) someDir: SomeDirective;
@ContentChildren(SomeDirective) someDirList !: QueryList<SomeDirective>;
}

Expand Down Expand Up @@ -1785,7 +1785,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild('myRef') myRef: any;
@ContentChild('myRef', {static: false}) myRef: any;
@ContentChildren('myRef1, myRef2, myRef3') myRefs: QueryList<any>;
}
@NgModule({declarations: [ContentQueryComponent]})
Expand Down Expand Up @@ -1910,9 +1910,9 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@ContentChild('myRef', {read: TemplateRef}) myRef: TemplateRef;
@ContentChild('myRef', {read: TemplateRef, static: false}) myRef: TemplateRef;
@ContentChildren('myRef1, myRef2, myRef3', {read: ElementRef}) myRefs: QueryList<ElementRef>;
@ContentChild(SomeDirective, {read: ElementRef}) someDir: ElementRef;
@ContentChild(SomeDirective, {read: ElementRef, static: false}) someDir: ElementRef;
@ContentChildren(SomeDirective, {read: TemplateRef}) someDirs: QueryList<TemplateRef>;
}
@NgModule({declarations: [ContentQueryComponent]})
Expand Down Expand Up @@ -1965,7 +1965,7 @@ describe('compiler compliance', () => {
\`
})
export class ContentQueryComponent {
@Input() @ContentChild('foo') foo: any;
@Input() @ContentChild('foo', {static: false}) foo: any;
}

@Component({
Expand Down Expand Up @@ -3138,7 +3138,7 @@ describe('compiler compliance', () => {
'spec.ts': `
import {Component, NgModule, ContentChild} from '@angular/core';
export class BaseClass {
@ContentChild('something') something: any;
@ContentChild('something', {static: false}) something: any;
}

@Component({
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,10 @@ describe('ngtsc behavioral tests', () => {
}
})
class FooCmp {
@ContentChild('bar', {read: TemplateRef}) child: any;
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
@ContentChildren(TemplateRef) children: any;
get aview(): any { return null; }
@ViewChild('accessor') set aview(value: any) {}
@ViewChild('accessor', {static: false}) set aview(value: any) {}
}
`);

Expand Down Expand Up @@ -1569,7 +1569,7 @@ describe('ngtsc behavioral tests', () => {
}
})
class FooCmp {
@ContentChild('bar', {read: TemplateRef}) child: any;
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
@ContentChildren(TemplateRef) children: any;
get aview(): any { return null; }
@ViewChild('accessor') set aview(value: any) {}
Expand Down Expand Up @@ -1601,11 +1601,11 @@ describe('ngtsc behavioral tests', () => {
template: '<div #foo></div>',
})
class FooCmp {
@ContentChild(forwardRef(() => TemplateRef)) child: any;
@ContentChild(forwardRef(() => TemplateRef), {static: false}) child: any;

@ContentChild(forwardRef(function() { return ViewContainerRef; })) child2: any;
@ContentChild(forwardRef(function() { return ViewContainerRef; }), {static: false}) child2: any;

@ContentChild((forwardRef((function() { return 'parens'; }) as any))) childInParens: any;
@ContentChild((forwardRef((function() { return 'parens'; }) as any)), {static: false}) childInParens: any;
}
`);

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Query {
read: any;
isViewQuery: boolean;
selector: any;
static?: boolean;
static: boolean;
}

export const createContentChildren = makeMetadataFactory<Query>(
Expand Down
14 changes: 8 additions & 6 deletions packages/compiler/test/core_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import * as core from '@angular/core';
typeExtends<compilerCore.Query, core.Query>();
typeExtends<core.Query, compilerCore.Query>();
compareRuntimeShape(
new core.ContentChild('someSelector'), compilerCore.createContentChild('someSelector'));
new core.ContentChild('someSelector', {static: false}),
compilerCore.createContentChild('someSelector', {static: false}));
compareRuntimeShape(
new core.ContentChild('someSelector', {read: 'someRead'}),
compilerCore.createContentChild('someSelector', {read: 'someRead'}));
new core.ContentChild('someSelector', {read: 'someRead', static: false}),
compilerCore.createContentChild('someSelector', {read: 'someRead', static: false}));
compareRuntimeShape(
new core.ContentChildren('someSelector'),
compilerCore.createContentChildren('someSelector'));
Expand All @@ -39,10 +40,11 @@ import * as core from '@angular/core';
compilerCore.createContentChildren(
'someSelector', {read: 'someRead', descendants: false}));
compareRuntimeShape(
new core.ViewChild('someSelector'), compilerCore.createViewChild('someSelector'));
new core.ViewChild('someSelector', {static: false}),
compilerCore.createViewChild('someSelector', {static: false}));
compareRuntimeShape(
new core.ViewChild('someSelector', {read: 'someRead'}),
compilerCore.createViewChild('someSelector', {read: 'someRead'}));
new core.ViewChild('someSelector', {read: 'someRead', static: false}),
compilerCore.createViewChild('someSelector', {read: 'someRead', static: false}));
compareRuntimeShape(
new core.ViewChildren('someSelector'), compilerCore.createViewChildren('someSelector'));
compareRuntimeShape(
Expand Down
34 changes: 19 additions & 15 deletions packages/compiler/test/directive_resolver_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class SomeDirectiveWithViewChildren {
c: any;
}

@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c', {static: false})}})
class SomeDirectiveWithContentChild {
@ContentChild('a') a: any;
@ContentChild('a', {static: false}) a: any;
c: any;
}

@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c', {static: false})}})
class SomeDirectiveWithViewChild {
@ViewChild('a') a: any;
@ViewChild('a', {static: false}) a: any;
c: any;
}

Expand Down Expand Up @@ -408,37 +408,41 @@ class SomeDirectiveWithoutMetadata {}

it('should append ContentChild', () => {
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChild);
expect(directiveMetadata.queries)
.toEqual({'c': new ContentChild('c'), 'a': new ContentChild('a')});
expect(directiveMetadata.queries).toEqual({
'c': new ContentChild('c', {static: false}),
'a': new ContentChild('a', {static: false})
});
});

it('should append ViewChild', () => {
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChild);
expect(directiveMetadata.queries)
.toEqual({'c': new ViewChild('c'), 'a': new ViewChild('a')});
expect(directiveMetadata.queries).toEqual({
'c': new ViewChild('c', {static: false}),
'a': new ViewChild('a', {static: false})
});
});

it('should support inheriting queries', () => {
@Directive({selector: 'p'})
class Parent {
@ContentChild('p1')
@ContentChild('p1', {static: false})
p1: any;
@ContentChild('p21')
@ContentChild('p21', {static: false})
p2: any;
}

class Child extends Parent {
@ContentChild('p22')
@ContentChild('p22', {static: false})
p2: any;
@ContentChild('p3')
@ContentChild('p3', {static: false})
p3: any;
}

const directiveMetadata = resolver.resolve(Child);
expect(directiveMetadata.queries).toEqual({
'p1': new ContentChild('p1'),
'p2': new ContentChild('p22'),
'p3': new ContentChild('p3')
'p1': new ContentChild('p1', {static: false}),
'p2': new ContentChild('p22', {static: false}),
'p3': new ContentChild('p3', {static: false})
});
});
});
Expand Down
Loading