Skip to content

Commit 84dd267

Browse files
alxhubmatsko
authored andcommitted
fix(core): require 'static' flag on queries in typings (#30639)
This commit makes the static flag on @ViewChild and @ContentChild required. BREAKING CHANGE: In Angular version 8, it's required that all @ViewChild and @ContentChild queries have a 'static' flag specifying whether the query is 'static' or 'dynamic'. The compiler previously sorted queries automatically, but in 8.0 developers are required to explicitly specify which behavior is wanted. This is a temporary requirement as part of a migration; see https://angular.io/guide/static-query-migration for more details. @ViewChildren and @ContentChildren queries are always dynamic, and so are unaffected. PR Close #30639
1 parent dc6406e commit 84dd267

21 files changed

Lines changed: 46 additions & 45 deletions

File tree

‎aio/content/examples/component-interaction/src/app/countdown-parent.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CountdownLocalVarParentComponent { }
3939
})
4040
export class CountdownViewChildParentComponent implements AfterViewInit {
4141

42-
@ViewChild(CountdownTimerComponent)
42+
@ViewChild(CountdownTimerComponent, {static: false})
4343
private timerComponent: CountdownTimerComponent;
4444

4545
seconds() { return 0; }

‎aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { AdComponent } from './ad.component';
2020
export class AdBannerComponent implements OnInit, OnDestroy {
2121
@Input() ads: AdItem[];
2222
currentAdIndex = -1;
23-
@ViewChild(AdDirective) adHost: AdDirective;
23+
@ViewChild(AdDirective, {static: true}) adHost: AdDirective;
2424
interval: any;
2525

2626
constructor(private componentFactoryResolver: ComponentFactoryResolver) { }

‎aio/content/examples/lifecycle-hooks/src/app/after-content.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class AfterContentComponent implements AfterContentChecked, AfterContentI
3434
comment = '';
3535

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

3939
// #enddocregion hooks
4040
constructor(private logger: LoggerService) {

‎aio/content/examples/lifecycle-hooks/src/app/after-view.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
3535
private prevHero = '';
3636

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

4040
// #enddocregion hooks
4141
constructor(private logger: LoggerService) {

‎aio/content/examples/lifecycle-hooks/src/app/do-check.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class DoCheckParentComponent {
8181
hero: Hero;
8282
power: string;
8383
title = 'DoCheck';
84-
@ViewChild(DoCheckComponent) childView: DoCheckComponent;
84+
@ViewChild(DoCheckComponent, {static: false}) childView: DoCheckComponent;
8585

8686
constructor() { this.reset(); }
8787

‎aio/content/examples/lifecycle-hooks/src/app/on-changes.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class OnChangesParentComponent {
5555
hero: Hero;
5656
power: string;
5757
title = 'OnChanges';
58-
@ViewChild(OnChangesComponent) childView: OnChangesComponent;
58+
@ViewChild(OnChangesComponent, {static: false}) childView: OnChangesComponent;
5959

6060
constructor() {
6161
this.reset();

‎aio/content/examples/template-syntax/src/app/hero-form.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Hero } from './hero';
1313
})
1414
export class HeroFormComponent {
1515
@Input() hero: Hero;
16-
@ViewChild('heroForm') form: NgForm;
16+
@ViewChild('heroForm', {static: false}) form: NgForm;
1717

1818
private _submitMessage = '';
1919

‎aio/content/examples/testing/src/app/shared/canvas.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Component, AfterViewInit, ViewChild } from '@angular/core';
66
})
77
export class CanvasComponent implements AfterViewInit {
88
blobSize: number;
9-
@ViewChild('sampleCanvas') sampleCanvas;
9+
@ViewChild('sampleCanvas', {static: false}) sampleCanvas;
1010

1111
constructor() { }
1212

‎aio/src/app/custom-elements/code/code-example.component.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ class HostComponent {
9696
path = 'code-path';
9797
hidecopy: boolean | string = false;
9898

99-
@ViewChild(CodeExampleComponent) codeExampleComponent: CodeExampleComponent;
99+
@ViewChild(CodeExampleComponent, {static: true}) codeExampleComponent: CodeExampleComponent;
100100
}

‎aio/src/app/custom-elements/code/code-tabs.component.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ describe('CodeTabsComponent', () => {
9292
`
9393
})
9494
class HostComponent {
95-
@ViewChild(CodeTabsComponent) codeTabsComponent: CodeTabsComponent;
95+
@ViewChild(CodeTabsComponent, {static: true}) codeTabsComponent: CodeTabsComponent;
9696
}

0 commit comments

Comments
 (0)