Skip to content

Commit ece8004

Browse files
crisbetommalerba
authored andcommitted
refactor: clean up explicit dynamic query usage (#17468)
Cleans up explicit usages of `static: false` in queries since it's no longer necessary.
1 parent 409e656 commit ece8004

File tree

132 files changed

+450
-500
lines changed

Some content is hidden

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

132 files changed

+450
-500
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', {static: false}) mainContent: ElementRef<HTMLElement>;
25-
@ViewChild('header', {static: false}) sectionHeader: ElementRef<HTMLElement>;
24+
@ViewChild('maincontent') mainContent: ElementRef<HTMLElement>;
25+
@ViewChild('header') sectionHeader: ElementRef<HTMLElement>;
2626

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

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,7 @@ class ComponentWithOnPushViewContainer {
11411141
template: `<dir-with-view-container></dir-with-view-container>`,
11421142
})
11431143
class ComponentWithChildViewContainer {
1144-
@ViewChild(DirectiveWithViewContainer, {
1145-
static: false
1146-
}) childWithViewContainer: DirectiveWithViewContainer;
1144+
@ViewChild(DirectiveWithViewContainer) childWithViewContainer: DirectiveWithViewContainer;
11471145

11481146
get childViewContainer() {
11491147
return this.childWithViewContainer.viewContainerRef;
@@ -1159,7 +1157,7 @@ class ComponentWithTemplateRef {
11591157
localValue: string;
11601158
dialogRef: DialogRef<any>;
11611159

1162-
@ViewChild(TemplateRef, {static: false}) templateRef: TemplateRef<any>;
1160+
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;
11631161

11641162
setDialogRef(dialogRef: DialogRef<any>): string {
11651163
this.dialogRef = dialogRef;

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ interface PeriodicElement {
6666
selector: 'do-not-use-abstract-cdk-popover-edit-base-test-component'
6767
})
6868
abstract class BaseTestComponent {
69-
@ViewChild('table', {static: false}) table: ElementRef;
69+
@ViewChild('table') table: ElementRef;
7070

7171
preservedValues = new FormValueContainer<PeriodicElement, {'name': string}>();
7272

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,16 @@ function expectMessage(el: Element, message: string) {
289289
`,
290290
})
291291
class TestApp {
292-
@ViewChild('element1', {static: false}) _element1: ElementRef<HTMLElement>;
292+
@ViewChild('element1') _element1: ElementRef<HTMLElement>;
293293
get element1(): Element { return this._element1.nativeElement; }
294294

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

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

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

304304

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, {static: false}) focusTrapDirective: CdkTrapFocus;
202+
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
203203
}
204204

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

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

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

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

276276
@Component({
@@ -281,5 +281,5 @@ class FocusTrapWithSvg {
281281
`
282282
})
283283
class FocusTrapWithoutFocusableElements {
284-
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
284+
@ViewChild(CdkTrapFocus) 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, {static: false}) dir: Dir;
161+
@ViewChild(Dir) 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, {static: false}) dir: Dir;
170+
@ViewChild(Dir) dir: Dir;
171171
}
172172

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

180180

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,8 +4431,8 @@ describe('CdkDrag', () => {
44314431
`
44324432
})
44334433
class StandaloneDraggable {
4434-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4435-
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
4434+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4435+
@ViewChild(CdkDrag) dragInstance: CdkDrag;
44364436
startedSpy = jasmine.createSpy('started spy');
44374437
endedSpy = jasmine.createSpy('ended spy');
44384438
releasedSpy = jasmine.createSpy('released spy');
@@ -4449,8 +4449,8 @@ class StandaloneDraggable {
44494449
`
44504450
})
44514451
class StandaloneDraggableWithOnPush {
4452-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4453-
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
4452+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4453+
@ViewChild(CdkDrag) dragInstance: CdkDrag;
44544454
}
44554455

44564456
@Component({
@@ -4463,7 +4463,7 @@ class StandaloneDraggableWithOnPush {
44634463
`
44644464
})
44654465
class StandaloneDraggableSvg {
4466-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<SVGElement>;
4466+
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
44674467
}
44684468

44694469
@Component({
@@ -4475,10 +4475,10 @@ class StandaloneDraggableSvg {
44754475
`
44764476
})
44774477
class StandaloneDraggableWithHandle {
4478-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4479-
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
4480-
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
4481-
@ViewChild(CdkDragHandle, {static: false}) handleInstance: CdkDragHandle;
4478+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4479+
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
4480+
@ViewChild(CdkDrag) dragInstance: CdkDrag;
4481+
@ViewChild(CdkDragHandle) handleInstance: CdkDragHandle;
44824482
}
44834483

44844484
@Component({
@@ -4493,8 +4493,8 @@ class StandaloneDraggableWithHandle {
44934493
`
44944494
})
44954495
class StandaloneDraggableWithDelayedHandle {
4496-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4497-
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
4496+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4497+
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
44984498
showHandle = false;
44994499
}
45004500

@@ -4513,8 +4513,8 @@ class StandaloneDraggableWithDelayedHandle {
45134513
`
45144514
})
45154515
class StandaloneDraggableWithIndirectHandle {
4516-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4517-
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
4516+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4517+
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
45184518
}
45194519

45204520

@@ -4538,7 +4538,7 @@ class StandaloneDraggableWithIndirectHandle {
45384538
`
45394539
})
45404540
class StandaloneDraggableWithMultipleHandles {
4541-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4541+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
45424542
@ViewChildren(CdkDragHandle) handles: QueryList<CdkDragHandle>;
45434543
}
45444544

@@ -4566,7 +4566,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
45664566
@Component({template: DROP_ZONE_FIXTURE_TEMPLATE})
45674567
class DraggableInDropZone {
45684568
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
4569-
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
4569+
@ViewChild(CdkDropList) dropInstance: CdkDropList;
45704570
items = [
45714571
{value: 'Zero', height: ITEM_HEIGHT, margin: 0},
45724572
{value: 'One', height: ITEM_HEIGHT, margin: 0},
@@ -4676,7 +4676,7 @@ const HORIZONTAL_FIXTURE_TEMPLATE = `
46764676
})
46774677
class DraggableInHorizontalDropZone {
46784678
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
4679-
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
4679+
@ViewChild(CdkDropList) dropInstance: CdkDropList;
46804680
items = [
46814681
{value: 'Zero', width: ITEM_WIDTH, margin: 0},
46824682
{value: 'One', width: ITEM_WIDTH, margin: 0},
@@ -4736,7 +4736,7 @@ class DraggableInScrollableHorizontalDropZone extends DraggableInHorizontalDropZ
47364736
`
47374737
})
47384738
class DraggableInDropZoneWithCustomPreview {
4739-
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
4739+
@ViewChild(CdkDropList) dropInstance: CdkDropList;
47404740
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
47414741
items = ['Zero', 'One', 'Two', 'Three'];
47424742
boundarySelector: string;
@@ -4762,7 +4762,7 @@ class DraggableInDropZoneWithCustomPreview {
47624762
`
47634763
})
47644764
class DraggableInDropZoneWithCustomTextOnlyPreview {
4765-
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
4765+
@ViewChild(CdkDropList) dropInstance: CdkDropList;
47664766
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
47674767
items = ['Zero', 'One', 'Two', 'Three'];
47684768
}
@@ -4956,9 +4956,9 @@ class ConnectedDropZonesViaGroupDirective extends ConnectedDropZones {
49564956
`
49574957
})
49584958
class DraggableWithAlternateRoot {
4959-
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
4960-
@ViewChild('dragRoot', {static: false}) dragRoot: ElementRef<HTMLElement>;
4961-
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
4959+
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
4960+
@ViewChild('dragRoot') dragRoot: ElementRef<HTMLElement>;
4961+
@ViewChild(CdkDrag) dragInstance: CdkDrag;
49624962
rootElementSelector: string;
49634963
}
49644964

@@ -5017,9 +5017,9 @@ class ConnectedDropZonesWithSingleItems {
50175017
`
50185018
})
50195019
class NestedDropListGroups {
5020-
@ViewChild('group', {static: false}) group: CdkDropListGroup<CdkDropList>;
5021-
@ViewChild('listOne', {static: false}) listOne: CdkDropList;
5022-
@ViewChild('listTwo', {static: false}) listTwo: CdkDropList;
5020+
@ViewChild('group') group: CdkDropListGroup<CdkDropList>;
5021+
@ViewChild('listOne') listOne: CdkDropList;
5022+
@ViewChild('listTwo') listTwo: CdkDropList;
50235023
}
50245024

50255025

@@ -5044,7 +5044,7 @@ class DraggableOnNgContainer {}
50445044
})
50455045
class DraggableInDropZoneWithoutEvents {
50465046
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
5047-
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
5047+
@ViewChild(CdkDropList) dropInstance: CdkDropList;
50485048
items = [
50495049
{value: 'Zero', height: ITEM_HEIGHT},
50505050
{value: 'One', height: ITEM_HEIGHT},
@@ -5184,8 +5184,8 @@ class WrappedDropContainerComponent {
51845184
</div>`
51855185
})
51865186
class NestedDragsComponent {
5187-
@ViewChild('container', {static: false}) container: ElementRef;
5188-
@ViewChild('item', {static: false}) item: ElementRef;
5187+
@ViewChild('container') container: ElementRef;
5188+
@ViewChild('item') item: ElementRef;
51895189

51905190
containerDragStartedSpy = jasmine.createSpy('container drag started spy');
51915191
containerDragMovedSpy = jasmine.createSpy('container drag moved spy');
@@ -5215,8 +5215,8 @@ class NestedDragsComponent {
52155215
})
52165216
class NestedDropZones {
52175217
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
5218-
@ViewChild('outerList', {static: false}) outerList: ElementRef<HTMLElement>;
5219-
@ViewChild('innerList', {static: false}) innerList: ElementRef<HTMLElement>;
5218+
@ViewChild('outerList') outerList: ElementRef<HTMLElement>;
5219+
@ViewChild('innerList') innerList: ElementRef<HTMLElement>;
52205220
items = ['Zero', 'One', 'Two', 'Three'];
52215221
}
52225222

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

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

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

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

9696
/** Arbitrary data to attach to this drag instance. */
9797
@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', {static: false}) contentEl: ElementRef;
231+
@ViewChild('contentEl') 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
@@ -574,9 +574,9 @@ describe('Overlay directives', () => {
574574
</ng-template>`,
575575
})
576576
class ConnectedOverlayDirectiveTest {
577-
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
578-
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
579-
@ViewChild('otherTrigger', {static: false}) otherTrigger: CdkOverlayOrigin;
577+
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
578+
@ViewChild('trigger') trigger: CdkOverlayOrigin;
579+
@ViewChild('otherTrigger') otherTrigger: CdkOverlayOrigin;
580580

581581
isOpen = false;
582582
width: number | string;
@@ -609,6 +609,6 @@ class ConnectedOverlayDirectiveTest {
609609
<ng-template cdk-connected-overlay>Menu content</ng-template>`,
610610
})
611611
class ConnectedOverlayPropertyInitOrder {
612-
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
613-
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
612+
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
613+
@ViewChild('trigger') trigger: CdkOverlayOrigin;
614614
}

src/cdk/overlay/overlay.spec.ts

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

985985
constructor(public viewContainerRef: ViewContainerRef) { }
986986
}

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, {static: false}) scrollable: CdkScrollable;
248-
@ViewChild('scrollingElement', {static: false}) scrollingElement: ElementRef<HTMLElement>;
247+
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
248+
@ViewChild('scrollingElement') scrollingElement: ElementRef<HTMLElement>;
249249
}
250250

251251

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

268268
const TEST_COMPONENTS = [ScrollingComponent, NestedScrollingComponent];

0 commit comments

Comments
 (0)