Skip to content

Commit e055753

Browse files
crisbetojelbourn
authored andcommitted
refactor: explicitly set static flag on all queries (#15682)
Explicitly marks all `ViewChild` and `ContentChild` queries so that the timing is consistent for apps using Ivy or ViewEngine. This PR resolves FW-1212.
1 parent 0a1c48f commit e055753

File tree

96 files changed

+354
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+354
-346
lines changed

src/a11y-demo/a11y-demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class AccessibilityDemoRoot implements OnDestroy {
2121

2222
private _routerSubscription = Subscription.EMPTY;
2323

24-
@ViewChild('maincontent') mainContent: ElementRef<HTMLElement>;
25-
@ViewChild('header') sectionHeader: ElementRef<HTMLElement>;
24+
@ViewChild('maincontent', {static: false}) mainContent: ElementRef<HTMLElement>;
25+
@ViewChild('header', {static: false}) sectionHeader: ElementRef<HTMLElement>;
2626

2727
navItems = [
2828
{name: 'Home', route: '.'},

src/a11y-demo/table/table-a11y.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const exampleData = [
3535
styleUrls: ['table-a11y.css'],
3636
})
3737
export class TableAccessibilityDemo implements OnInit {
38-
@ViewChild(MatSort) sort: MatSort;
39-
@ViewChild(MatPaginator) pager: MatPaginator;
38+
@ViewChild(MatSort, {static: false}) sort: MatSort;
39+
@ViewChild(MatPaginator, {static: false}) pager: MatPaginator;
4040

4141
displayedColumns = ['name', 'color', 'age'];
4242
basicDataSource: BasicDataSource;

src/cdk-experimental/dialog/dialog.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,9 @@ class ComponentWithOnPushViewContainer {
10791079
template: `<dir-with-view-container></dir-with-view-container>`,
10801080
})
10811081
class ComponentWithChildViewContainer {
1082-
@ViewChild(DirectiveWithViewContainer) childWithViewContainer: DirectiveWithViewContainer;
1082+
@ViewChild(DirectiveWithViewContainer, {
1083+
static: false
1084+
}) childWithViewContainer: DirectiveWithViewContainer;
10831085

10841086
get childViewContainer() {
10851087
return this.childWithViewContainer.viewContainerRef;
@@ -1095,7 +1097,7 @@ class ComponentWithTemplateRef {
10951097
localValue: string;
10961098
dialogRef: DialogRef<any>;
10971099

1098-
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;
1100+
@ViewChild(TemplateRef, {static: false}) templateRef: TemplateRef<any>;
10991101

11001102
setDialogRef(dialogRef: DialogRef<any>): string {
11011103
this.dialogRef = dialogRef;

src/cdk/a11y/aria-describer/aria-describer.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ function expectMessage(el: Element, message: string) {
189189
`,
190190
})
191191
class TestApp {
192-
@ViewChild('element1') _element1: ElementRef<HTMLElement>;
192+
@ViewChild('element1', {static: false}) _element1: ElementRef<HTMLElement>;
193193
get element1(): Element { return this._element1.nativeElement; }
194194

195-
@ViewChild('element2') _element2: ElementRef<HTMLElement>;
195+
@ViewChild('element2', {static: false}) _element2: ElementRef<HTMLElement>;
196196
get element2(): Element { return this._element2.nativeElement; }
197197

198-
@ViewChild('element3') _element3: ElementRef<HTMLElement>;
198+
@ViewChild('element3', {static: false}) _element3: ElementRef<HTMLElement>;
199199
get element3(): Element { return this._element3.nativeElement; }
200200

201-
@ViewChild('element4') _element4: ElementRef<HTMLElement>;
201+
@ViewChild('element4', {static: false}) _element4: ElementRef<HTMLElement>;
202202
get element4(): Element { return this._element4.nativeElement; }
203203

204204

src/cdk/a11y/focus-trap/focus-trap.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('FocusTrap', () => {
199199
`
200200
})
201201
class SimpleFocusTrap {
202-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
202+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
203203
}
204204

205205
@Component({
@@ -212,7 +212,7 @@ class SimpleFocusTrap {
212212
`
213213
})
214214
class FocusTrapWithAutoCapture {
215-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
215+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
216216
showTrappedRegion = false;
217217
}
218218

@@ -226,7 +226,7 @@ class FocusTrapWithAutoCapture {
226226
`
227227
})
228228
class FocusTrapWithBindings {
229-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
229+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
230230
renderFocusTrap = true;
231231
_isFocusTrapEnabled = true;
232232
}
@@ -246,7 +246,7 @@ class FocusTrapWithBindings {
246246
`
247247
})
248248
class FocusTrapTargets {
249-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
249+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
250250
}
251251

252252
@Component({
@@ -257,7 +257,7 @@ class FocusTrapTargets {
257257
`
258258
})
259259
class FocusTrapUnfocusableTarget {
260-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
260+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
261261
}
262262

263263
@Component({
@@ -270,7 +270,7 @@ class FocusTrapUnfocusableTarget {
270270
`
271271
})
272272
class FocusTrapWithSvg {
273-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
273+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
274274
}
275275

276276
@Component({
@@ -281,5 +281,5 @@ class FocusTrapWithSvg {
281281
`
282282
})
283283
class FocusTrapWithoutFocusableElements {
284-
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
284+
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
285285
}

src/cdk/bidi/directionality.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('Directionality', () => {
158158
`
159159
})
160160
class ElementWithDir {
161-
@ViewChild(Dir) dir: Dir;
161+
@ViewChild(Dir, {static: false}) dir: Dir;
162162
direction = 'rtl';
163163
changeCount = 0;
164164
}
@@ -167,14 +167,14 @@ class ElementWithDir {
167167
template: '<div dir="auto"></div>'
168168
})
169169
class ElementWithPredefinedAutoDir {
170-
@ViewChild(Dir) dir: Dir;
170+
@ViewChild(Dir, {static: false}) dir: Dir;
171171
}
172172

173173
@Component({
174174
template: '<div dir="RTL"></div>'
175175
})
176176
class ElementWithPredefinedUppercaseDir {
177-
@ViewChild(Dir) dir: Dir;
177+
@ViewChild(Dir, {static: false}) dir: Dir;
178178
}
179179

180180

src/cdk/drag-drop/directives/drag.spec.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,8 +3104,8 @@ describe('CdkDrag', () => {
31043104
`
31053105
})
31063106
class StandaloneDraggable {
3107-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3108-
@ViewChild(CdkDrag) dragInstance: CdkDrag;
3107+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3108+
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
31093109
startedSpy = jasmine.createSpy('started spy');
31103110
endedSpy = jasmine.createSpy('ended spy');
31113111
releasedSpy = jasmine.createSpy('released spy');
@@ -3121,8 +3121,8 @@ class StandaloneDraggable {
31213121
`
31223122
})
31233123
class StandaloneDraggableWithOnPush {
3124-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3125-
@ViewChild(CdkDrag) dragInstance: CdkDrag;
3124+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3125+
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
31263126
}
31273127

31283128
@Component({
@@ -3135,7 +3135,7 @@ class StandaloneDraggableWithOnPush {
31353135
`
31363136
})
31373137
class StandaloneDraggableSvg {
3138-
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
3138+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<SVGElement>;
31393139
}
31403140

31413141
@Component({
@@ -3147,10 +3147,10 @@ class StandaloneDraggableSvg {
31473147
`
31483148
})
31493149
class StandaloneDraggableWithHandle {
3150-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3151-
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
3152-
@ViewChild(CdkDrag) dragInstance: CdkDrag;
3153-
@ViewChild(CdkDragHandle) handleInstance: CdkDragHandle;
3150+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3151+
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
3152+
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
3153+
@ViewChild(CdkDragHandle, {static: false}) handleInstance: CdkDragHandle;
31543154
}
31553155

31563156
@Component({
@@ -3165,8 +3165,8 @@ class StandaloneDraggableWithHandle {
31653165
`
31663166
})
31673167
class StandaloneDraggableWithDelayedHandle {
3168-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3169-
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
3168+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3169+
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
31703170
showHandle = false;
31713171
}
31723172

@@ -3185,8 +3185,8 @@ class StandaloneDraggableWithDelayedHandle {
31853185
`
31863186
})
31873187
class StandaloneDraggableWithIndirectHandle {
3188-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3189-
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
3188+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3189+
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
31903190
}
31913191

31923192

@@ -3210,7 +3210,7 @@ class StandaloneDraggableWithIndirectHandle {
32103210
`
32113211
})
32123212
class StandaloneDraggableWithMultipleHandles {
3213-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3213+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
32143214
@ViewChildren(CdkDragHandle) handles: QueryList<CdkDragHandle>;
32153215
}
32163216

@@ -3236,7 +3236,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
32363236
@Component({template: DROP_ZONE_FIXTURE_TEMPLATE})
32373237
class DraggableInDropZone {
32383238
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
3239-
@ViewChild(CdkDropList) dropInstance: CdkDropList;
3239+
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
32403240
items = [
32413241
{value: 'Zero', height: ITEM_HEIGHT, margin: 0},
32423242
{value: 'One', height: ITEM_HEIGHT, margin: 0},
@@ -3292,7 +3292,7 @@ class DraggableInOnPushDropZone extends DraggableInDropZone {}
32923292
})
32933293
class DraggableInHorizontalDropZone {
32943294
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
3295-
@ViewChild(CdkDropList) dropInstance: CdkDropList;
3295+
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
32963296
items = [
32973297
{value: 'Zero', width: ITEM_WIDTH, margin: 0},
32983298
{value: 'One', width: ITEM_WIDTH, margin: 0},
@@ -3326,7 +3326,7 @@ class DraggableInHorizontalDropZone {
33263326
`
33273327
})
33283328
class DraggableInDropZoneWithCustomPreview {
3329-
@ViewChild(CdkDropList) dropInstance: CdkDropList;
3329+
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
33303330
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
33313331
items = ['Zero', 'One', 'Two', 'Three'];
33323332
boundarySelector: string;
@@ -3471,9 +3471,9 @@ class ConnectedDropZonesViaGroupDirective extends ConnectedDropZones {
34713471
`
34723472
})
34733473
class DraggableWithAlternateRoot {
3474-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
3475-
@ViewChild('dragRoot') dragRoot: ElementRef<HTMLElement>;
3476-
@ViewChild(CdkDrag) dragInstance: CdkDrag;
3474+
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
3475+
@ViewChild('dragRoot', {static: false}) dragRoot: ElementRef<HTMLElement>;
3476+
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
34773477
rootElementSelector: string;
34783478
}
34793479

@@ -3532,9 +3532,9 @@ class ConnectedDropZonesWithSingleItems {
35323532
`
35333533
})
35343534
class NestedDropListGroups {
3535-
@ViewChild('group') group: CdkDropListGroup<CdkDropList>;
3536-
@ViewChild('listOne') listOne: CdkDropList;
3537-
@ViewChild('listTwo') listTwo: CdkDropList;
3535+
@ViewChild('group', {static: false}) group: CdkDropListGroup<CdkDropList>;
3536+
@ViewChild('listOne', {static: false}) listOne: CdkDropList;
3537+
@ViewChild('listTwo', {static: false}) listTwo: CdkDropList;
35383538
}
35393539

35403540

@@ -3559,7 +3559,7 @@ class DraggableOnNgContainer {}
35593559
})
35603560
class DraggableInDropZoneWithoutEvents {
35613561
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
3562-
@ViewChild(CdkDropList) dropInstance: CdkDropList;
3562+
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
35633563
items = [
35643564
{value: 'Zero', height: ITEM_HEIGHT},
35653565
{value: 'One', height: ITEM_HEIGHT},

src/cdk/drag-drop/directives/drag.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
8585
@ContentChildren(CdkDragHandle, {descendants: true}) _handles: QueryList<CdkDragHandle>;
8686

8787
/** Element that will be used as a template to create the draggable item's preview. */
88-
@ContentChild(CdkDragPreview) _previewTemplate: CdkDragPreview;
88+
@ContentChild(CdkDragPreview, {static: false}) _previewTemplate: CdkDragPreview;
8989

9090
/** Template for placeholder element rendered to show where a draggable would be dropped. */
91-
@ContentChild(CdkDragPlaceholder) _placeholderTemplate: CdkDragPlaceholder;
91+
@ContentChild(CdkDragPlaceholder, {static: false}) _placeholderTemplate: CdkDragPlaceholder;
9292

9393
/** Arbitrary data to attach to this drag instance. */
9494
@Input('cdkDragData') data: T;

src/cdk/observers/observe-content.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,6 @@ class ComponentWithDebouncedListener {
228228
template: `<div #contentEl>{{text}}</div>`
229229
})
230230
class UnobservedComponentWithTextContent {
231-
@ViewChild('contentEl') contentEl: ElementRef;
231+
@ViewChild('contentEl', {static: false}) contentEl: ElementRef;
232232
text = '';
233233
}

src/cdk/overlay/overlay-directives.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ describe('Overlay directives', () => {
539539
</ng-template>`,
540540
})
541541
class ConnectedOverlayDirectiveTest {
542-
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
543-
@ViewChild('trigger') trigger: CdkOverlayOrigin;
544-
@ViewChild('otherTrigger') otherTrigger: CdkOverlayOrigin;
542+
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
543+
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
544+
@ViewChild('otherTrigger', {static: false}) otherTrigger: CdkOverlayOrigin;
545545

546546
isOpen = false;
547547
width: number | string;
@@ -574,6 +574,6 @@ class ConnectedOverlayDirectiveTest {
574574
<ng-template cdk-connected-overlay>Menu content</ng-template>`,
575575
})
576576
class ConnectedOverlayPropertyInitOrder {
577-
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
578-
@ViewChild('trigger') trigger: CdkOverlayOrigin;
577+
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
578+
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
579579
}

src/cdk/overlay/overlay.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ class PizzaMsg { }
948948
/** Test-bed component that contains a TempatePortal and an ElementRef. */
949949
@Component({template: `<ng-template cdk-portal>Cake</ng-template>`})
950950
class TestComponentWithTemplatePortals {
951-
@ViewChild(CdkPortal) templatePortal: CdkPortal;
951+
@ViewChild(CdkPortal, {static: false}) templatePortal: CdkPortal;
952952

953953
constructor(public viewContainerRef: ViewContainerRef) { }
954954
}

src/cdk/scrolling/scroll-dispatcher.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ describe('ScrollDispatcher', () => {
244244
template: `<div #scrollingElement cdk-scrollable style="height: 9999px"></div>`
245245
})
246246
class ScrollingComponent {
247-
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
248-
@ViewChild('scrollingElement') scrollingElement: ElementRef<HTMLElement>;
247+
@ViewChild(CdkScrollable, {static: false}) scrollable: CdkScrollable;
248+
@ViewChild('scrollingElement', {static: false}) scrollingElement: ElementRef<HTMLElement>;
249249
}
250250

251251

@@ -262,7 +262,7 @@ class ScrollingComponent {
262262
`
263263
})
264264
class NestedScrollingComponent {
265-
@ViewChild('interestingElement') interestingElement: ElementRef<HTMLElement>;
265+
@ViewChild('interestingElement', {static: false}) interestingElement: ElementRef<HTMLElement>;
266266
}
267267

268268
const TEST_COMPONENTS = [ScrollingComponent, NestedScrollingComponent];

src/cdk/scrolling/scrollable.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ describe('CdkScrollable', () => {
241241
})
242242
class ScrollableViewport {
243243
@Input() dir: Direction;
244-
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
245-
@ViewChild('scrollContainer') scrollContainer: ElementRef<Element>;
246-
@ViewChild('firstRowStart') firstRowStart: ElementRef<Element>;
247-
@ViewChild('firstRowEnd') firstRowEnd: ElementRef<Element>;
248-
@ViewChild('lastRowStart') lastRowStart: ElementRef<Element>;
249-
@ViewChild('lastRowEnd') lastRowEnd: ElementRef<Element>;
244+
@ViewChild(CdkScrollable, {static: false}) scrollable: CdkScrollable;
245+
@ViewChild('scrollContainer', {static: false}) scrollContainer: ElementRef<Element>;
246+
@ViewChild('firstRowStart', {static: false}) firstRowStart: ElementRef<Element>;
247+
@ViewChild('firstRowEnd', {static: false}) firstRowEnd: ElementRef<Element>;
248+
@ViewChild('lastRowStart', {static: false}) lastRowStart: ElementRef<Element>;
249+
@ViewChild('lastRowEnd', {static: false}) lastRowEnd: ElementRef<Element>;
250250
}

src/cdk/stepper/stepper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class CdkStep implements OnChanges {
118118
_displayDefaultIndicatorType: boolean;
119119

120120
/** Template for step label if it exists. */
121-
@ContentChild(CdkStepLabel) stepLabel: CdkStepLabel;
121+
@ContentChild(CdkStepLabel, {static: false}) stepLabel: CdkStepLabel;
122122

123123
/** Template for step content. */
124124
@ViewChild(TemplateRef, {static: true}) content: TemplateRef<any>;

0 commit comments

Comments
 (0)