Skip to content

Commit

Permalink
refactor: clean up explicit dynamic query usage (#17468)
Browse files Browse the repository at this point in the history
Cleans up explicit usages of `static: false` in queries since it's no longer necessary.
  • Loading branch information
crisbeto authored and mmalerba committed Oct 24, 2019
1 parent 409e656 commit ece8004
Show file tree
Hide file tree
Showing 132 changed files with 450 additions and 500 deletions.
4 changes: 2 additions & 2 deletions src/a11y-demo/a11y-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class AccessibilityDemoRoot implements OnDestroy {

private _routerSubscription = Subscription.EMPTY;

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

navItems = [
{name: 'Home', route: '.'},
Expand Down
6 changes: 2 additions & 4 deletions src/cdk-experimental/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,7 @@ class ComponentWithOnPushViewContainer {
template: `<dir-with-view-container></dir-with-view-container>`,
})
class ComponentWithChildViewContainer {
@ViewChild(DirectiveWithViewContainer, {
static: false
}) childWithViewContainer: DirectiveWithViewContainer;
@ViewChild(DirectiveWithViewContainer) childWithViewContainer: DirectiveWithViewContainer;

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

@ViewChild(TemplateRef, {static: false}) templateRef: TemplateRef<any>;
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;

setDialogRef(dialogRef: DialogRef<any>): string {
this.dialogRef = dialogRef;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk-experimental/popover-edit/popover-edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface PeriodicElement {
selector: 'do-not-use-abstract-cdk-popover-edit-base-test-component'
})
abstract class BaseTestComponent {
@ViewChild('table', {static: false}) table: ElementRef;
@ViewChild('table') table: ElementRef;

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

Expand Down
8 changes: 4 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ function expectMessage(el: Element, message: string) {
`,
})
class TestApp {
@ViewChild('element1', {static: false}) _element1: ElementRef<HTMLElement>;
@ViewChild('element1') _element1: ElementRef<HTMLElement>;
get element1(): Element { return this._element1.nativeElement; }

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

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

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


Expand Down
14 changes: 7 additions & 7 deletions src/cdk/a11y/focus-trap/focus-trap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('FocusTrap', () => {
`
})
class SimpleFocusTrap {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
}

@Component({
Expand All @@ -212,7 +212,7 @@ class SimpleFocusTrap {
`
})
class FocusTrapWithAutoCapture {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
showTrappedRegion = false;
}

Expand All @@ -226,7 +226,7 @@ class FocusTrapWithAutoCapture {
`
})
class FocusTrapWithBindings {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
renderFocusTrap = true;
_isFocusTrapEnabled = true;
}
Expand All @@ -246,7 +246,7 @@ class FocusTrapWithBindings {
`
})
class FocusTrapTargets {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
}

@Component({
Expand All @@ -257,7 +257,7 @@ class FocusTrapTargets {
`
})
class FocusTrapUnfocusableTarget {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
}

@Component({
Expand All @@ -270,7 +270,7 @@ class FocusTrapUnfocusableTarget {
`
})
class FocusTrapWithSvg {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
}

@Component({
Expand All @@ -281,5 +281,5 @@ class FocusTrapWithSvg {
`
})
class FocusTrapWithoutFocusableElements {
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
}
6 changes: 3 additions & 3 deletions src/cdk/bidi/directionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Directionality', () => {
`
})
class ElementWithDir {
@ViewChild(Dir, {static: false}) dir: Dir;
@ViewChild(Dir) dir: Dir;
direction = 'rtl';
changeCount = 0;
}
Expand All @@ -167,14 +167,14 @@ class ElementWithDir {
template: '<div dir="auto"></div>'
})
class ElementWithPredefinedAutoDir {
@ViewChild(Dir, {static: false}) dir: Dir;
@ViewChild(Dir) dir: Dir;
}

@Component({
template: '<div dir="RTL"></div>'
})
class ElementWithPredefinedUppercaseDir {
@ViewChild(Dir, {static: false}) dir: Dir;
@ViewChild(Dir) dir: Dir;
}


Expand Down
58 changes: 29 additions & 29 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4431,8 +4431,8 @@ describe('CdkDrag', () => {
`
})
class StandaloneDraggable {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag) dragInstance: CdkDrag;
startedSpy = jasmine.createSpy('started spy');
endedSpy = jasmine.createSpy('ended spy');
releasedSpy = jasmine.createSpy('released spy');
Expand All @@ -4449,8 +4449,8 @@ class StandaloneDraggable {
`
})
class StandaloneDraggableWithOnPush {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag) dragInstance: CdkDrag;
}

@Component({
Expand All @@ -4463,7 +4463,7 @@ class StandaloneDraggableWithOnPush {
`
})
class StandaloneDraggableSvg {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<SVGElement>;
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
}

@Component({
Expand All @@ -4475,10 +4475,10 @@ class StandaloneDraggableSvg {
`
})
class StandaloneDraggableWithHandle {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
@ViewChild(CdkDragHandle, {static: false}) handleInstance: CdkDragHandle;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag) dragInstance: CdkDrag;
@ViewChild(CdkDragHandle) handleInstance: CdkDragHandle;
}

@Component({
Expand All @@ -4493,8 +4493,8 @@ class StandaloneDraggableWithHandle {
`
})
class StandaloneDraggableWithDelayedHandle {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
showHandle = false;
}

Expand All @@ -4513,8 +4513,8 @@ class StandaloneDraggableWithDelayedHandle {
`
})
class StandaloneDraggableWithIndirectHandle {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement', {static: false}) handleElement: ElementRef<HTMLElement>;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
}


Expand All @@ -4538,7 +4538,7 @@ class StandaloneDraggableWithIndirectHandle {
`
})
class StandaloneDraggableWithMultipleHandles {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChildren(CdkDragHandle) handles: QueryList<CdkDragHandle>;
}

Expand Down Expand Up @@ -4566,7 +4566,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
@Component({template: DROP_ZONE_FIXTURE_TEMPLATE})
class DraggableInDropZone {
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
items = [
{value: 'Zero', height: ITEM_HEIGHT, margin: 0},
{value: 'One', height: ITEM_HEIGHT, margin: 0},
Expand Down Expand Up @@ -4676,7 +4676,7 @@ const HORIZONTAL_FIXTURE_TEMPLATE = `
})
class DraggableInHorizontalDropZone {
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
items = [
{value: 'Zero', width: ITEM_WIDTH, margin: 0},
{value: 'One', width: ITEM_WIDTH, margin: 0},
Expand Down Expand Up @@ -4736,7 +4736,7 @@ class DraggableInScrollableHorizontalDropZone extends DraggableInHorizontalDropZ
`
})
class DraggableInDropZoneWithCustomPreview {
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
items = ['Zero', 'One', 'Two', 'Three'];
boundarySelector: string;
Expand All @@ -4762,7 +4762,7 @@ class DraggableInDropZoneWithCustomPreview {
`
})
class DraggableInDropZoneWithCustomTextOnlyPreview {
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
items = ['Zero', 'One', 'Two', 'Three'];
}
Expand Down Expand Up @@ -4956,9 +4956,9 @@ class ConnectedDropZonesViaGroupDirective extends ConnectedDropZones {
`
})
class DraggableWithAlternateRoot {
@ViewChild('dragElement', {static: false}) dragElement: ElementRef<HTMLElement>;
@ViewChild('dragRoot', {static: false}) dragRoot: ElementRef<HTMLElement>;
@ViewChild(CdkDrag, {static: false}) dragInstance: CdkDrag;
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild('dragRoot') dragRoot: ElementRef<HTMLElement>;
@ViewChild(CdkDrag) dragInstance: CdkDrag;
rootElementSelector: string;
}

Expand Down Expand Up @@ -5017,9 +5017,9 @@ class ConnectedDropZonesWithSingleItems {
`
})
class NestedDropListGroups {
@ViewChild('group', {static: false}) group: CdkDropListGroup<CdkDropList>;
@ViewChild('listOne', {static: false}) listOne: CdkDropList;
@ViewChild('listTwo', {static: false}) listTwo: CdkDropList;
@ViewChild('group') group: CdkDropListGroup<CdkDropList>;
@ViewChild('listOne') listOne: CdkDropList;
@ViewChild('listTwo') listTwo: CdkDropList;
}


Expand All @@ -5044,7 +5044,7 @@ class DraggableOnNgContainer {}
})
class DraggableInDropZoneWithoutEvents {
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
items = [
{value: 'Zero', height: ITEM_HEIGHT},
{value: 'One', height: ITEM_HEIGHT},
Expand Down Expand Up @@ -5184,8 +5184,8 @@ class WrappedDropContainerComponent {
</div>`
})
class NestedDragsComponent {
@ViewChild('container', {static: false}) container: ElementRef;
@ViewChild('item', {static: false}) item: ElementRef;
@ViewChild('container') container: ElementRef;
@ViewChild('item') item: ElementRef;

containerDragStartedSpy = jasmine.createSpy('container drag started spy');
containerDragMovedSpy = jasmine.createSpy('container drag moved spy');
Expand Down Expand Up @@ -5215,8 +5215,8 @@ class NestedDragsComponent {
})
class NestedDropZones {
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@ViewChild('outerList', {static: false}) outerList: ElementRef<HTMLElement>;
@ViewChild('innerList', {static: false}) innerList: ElementRef<HTMLElement>;
@ViewChild('outerList') outerList: ElementRef<HTMLElement>;
@ViewChild('innerList') innerList: ElementRef<HTMLElement>;
items = ['Zero', 'One', 'Two', 'Three'];
}

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
@ContentChildren(CdkDragHandle, {descendants: true}) _handles: QueryList<CdkDragHandle>;

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

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

/** Arbitrary data to attach to this drag instance. */
@Input('cdkDragData') data: T;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/observers/observe-content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,6 @@ class ComponentWithDebouncedListener {
template: `<div #contentEl>{{text}}</div>`
})
class UnobservedComponentWithTextContent {
@ViewChild('contentEl', {static: false}) contentEl: ElementRef;
@ViewChild('contentEl') contentEl: ElementRef;
text = '';
}
10 changes: 5 additions & 5 deletions src/cdk/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ describe('Overlay directives', () => {
</ng-template>`,
})
class ConnectedOverlayDirectiveTest {
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
@ViewChild('otherTrigger', {static: false}) otherTrigger: CdkOverlayOrigin;
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger') trigger: CdkOverlayOrigin;
@ViewChild('otherTrigger') otherTrigger: CdkOverlayOrigin;

isOpen = false;
width: number | string;
Expand Down Expand Up @@ -609,6 +609,6 @@ class ConnectedOverlayDirectiveTest {
<ng-template cdk-connected-overlay>Menu content</ng-template>`,
})
class ConnectedOverlayPropertyInitOrder {
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger') trigger: CdkOverlayOrigin;
}
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ class PizzaMsg { }
/** Test-bed component that contains a TempatePortal and an ElementRef. */
@Component({template: `<ng-template cdk-portal>Cake</ng-template>`})
class TestComponentWithTemplatePortals {
@ViewChild(CdkPortal, {static: false}) templatePortal: CdkPortal;
@ViewChild(CdkPortal) templatePortal: CdkPortal;

constructor(public viewContainerRef: ViewContainerRef) { }
}
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/scrolling/scroll-dispatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ describe('ScrollDispatcher', () => {
template: `<div #scrollingElement cdk-scrollable style="height: 9999px"></div>`
})
class ScrollingComponent {
@ViewChild(CdkScrollable, {static: false}) scrollable: CdkScrollable;
@ViewChild('scrollingElement', {static: false}) scrollingElement: ElementRef<HTMLElement>;
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
@ViewChild('scrollingElement') scrollingElement: ElementRef<HTMLElement>;
}


Expand All @@ -262,7 +262,7 @@ class ScrollingComponent {
`
})
class NestedScrollingComponent {
@ViewChild('interestingElement', {static: false}) interestingElement: ElementRef<HTMLElement>;
@ViewChild('interestingElement') interestingElement: ElementRef<HTMLElement>;
}

const TEST_COMPONENTS = [ScrollingComponent, NestedScrollingComponent];
Expand Down
Loading

0 comments on commit ece8004

Please sign in to comment.