Skip to content

refactor: explicitly set static flag on all queries #15680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2019
Merged
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
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') mainContent: ElementRef<HTMLElement>;
@ViewChild('header') sectionHeader: ElementRef<HTMLElement>;
@ViewChild('maincontent', {static: false}) mainContent: ElementRef<HTMLElement>;
@ViewChild('header', {static: false}) sectionHeader: ElementRef<HTMLElement>;

navItems = [
{name: 'Home', route: '.'},
Expand Down
4 changes: 2 additions & 2 deletions src/a11y-demo/table/table-a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const exampleData = [
styleUrls: ['table-a11y.css'],
})
export class TableAccessibilityDemo implements OnInit {
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatPaginator) pager: MatPaginator;
@ViewChild(MatSort, {static: true}) sort: MatSort;
@ViewChild(MatPaginator, {static: true}) pager: MatPaginator;

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

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

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

setDialogRef(dialogRef: DialogRef<any>): string {
this.dialogRef = dialogRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function finishInit(fixture: ComponentFixture<any>) {
encapsulation: ViewEncapsulation.None,
})
class AutoSizeVirtualScroll {
@ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;
@ViewChild(CdkVirtualScrollViewport, {static: true}) viewport: CdkVirtualScrollViewport;

@Input() orientation = 'vertical';
@Input() viewportSize = 200;
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 @@ -189,16 +189,16 @@ function expectMessage(el: Element, message: string) {
`,
})
class TestApp {
@ViewChild('element1') _element1: ElementRef<HTMLElement>;
@ViewChild('element1', {static: false}) _element1: ElementRef<HTMLElement>;
get element1(): Element { return this._element1.nativeElement; }

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

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

@ViewChild('element4') _element4: ElementRef<HTMLElement>;
@ViewChild('element4', {static: false}) _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) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus, {static: false}) focusTrapDirective: CdkTrapFocus;
}

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

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

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

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

@Component({
Expand All @@ -281,5 +281,5 @@ class FocusTrapWithSvg {
`
})
class FocusTrapWithoutFocusableElements {
@ViewChild(CdkTrapFocus) focusTrapDirective: CdkTrapFocus;
@ViewChild(CdkTrapFocus, {static: false}) 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) dir: Dir;
@ViewChild(Dir, {static: false}) dir: Dir;
direction = 'rtl';
changeCount = 0;
}
Expand All @@ -167,14 +167,14 @@ class ElementWithDir {
template: '<div dir="auto"></div>'
})
class ElementWithPredefinedAutoDir {
@ViewChild(Dir) dir: Dir;
@ViewChild(Dir, {static: false}) dir: Dir;
}

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


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

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

@Component({
Expand All @@ -3239,10 +3239,10 @@ class StandaloneDraggableSvg {
`
})
class StandaloneDraggableWithHandle {
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
@ViewChild('handleElement') handleElement: ElementRef<HTMLElement>;
@ViewChild(CdkDrag) dragInstance: CdkDrag;
@ViewChild(CdkDragHandle) handleInstance: CdkDragHandle;
@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;
}

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

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


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

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

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


Expand All @@ -3651,7 +3651,7 @@ class DraggableOnNgContainer {}
})
class DraggableInDropZoneWithoutEvents {
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@ViewChild(CdkDropList, {static: false}) dropInstance: CdkDropList;
items = [
{value: 'Zero', height: ITEM_HEIGHT},
{value: 'One', height: ITEM_HEIGHT},
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 @@ -85,10 +85,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) _previewTemplate: CdkDragPreview;
@ContentChild(CdkDragPreview, {static: false}) _previewTemplate: CdkDragPreview;

/** Template for placeholder element rendered to show where a draggable would be dropped. */
@ContentChild(CdkDragPlaceholder) _placeholderTemplate: CdkDragPlaceholder;
@ContentChild(CdkDragPlaceholder, {static: false}) _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') contentEl: ElementRef;
@ViewChild('contentEl', {static: false}) 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 @@ -539,9 +539,9 @@ describe('Overlay directives', () => {
</ng-template>`,
})
class ConnectedOverlayDirectiveTest {
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger') trigger: CdkOverlayOrigin;
@ViewChild('otherTrigger') otherTrigger: CdkOverlayOrigin;
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger', {static: false}) trigger: CdkOverlayOrigin;
@ViewChild('otherTrigger', {static: false}) otherTrigger: CdkOverlayOrigin;

isOpen = false;
width: number | string;
Expand Down Expand Up @@ -574,6 +574,6 @@ class ConnectedOverlayDirectiveTest {
<ng-template cdk-connected-overlay>Menu content</ng-template>`,
})
class ConnectedOverlayPropertyInitOrder {
@ViewChild(CdkConnectedOverlay) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger') trigger: CdkOverlayOrigin;
@ViewChild(CdkConnectedOverlay, {static: false}) connectedOverlayDirective: CdkConnectedOverlay;
@ViewChild('trigger', {static: false}) 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 @@ -948,7 +948,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) templatePortal: CdkPortal;
@ViewChild(CdkPortal, {static: false}) 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) scrollable: CdkScrollable;
@ViewChild('scrollingElement') scrollingElement: ElementRef<HTMLElement>;
@ViewChild(CdkScrollable, {static: false}) scrollable: CdkScrollable;
@ViewChild('scrollingElement', {static: false}) scrollingElement: ElementRef<HTMLElement>;
}


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

const TEST_COMPONENTS = [ScrollingComponent, NestedScrollingComponent];
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/scrolling/scrollable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ describe('CdkScrollable', () => {
})
class ScrollableViewport {
@Input() dir: Direction;
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
@ViewChild('scrollContainer') scrollContainer: ElementRef<Element>;
@ViewChild('firstRowStart') firstRowStart: ElementRef<Element>;
@ViewChild('firstRowEnd') firstRowEnd: ElementRef<Element>;
@ViewChild('lastRowStart') lastRowStart: ElementRef<Element>;
@ViewChild('lastRowEnd') lastRowEnd: ElementRef<Element>;
@ViewChild(CdkScrollable, {static: false}) scrollable: CdkScrollable;
@ViewChild('scrollContainer', {static: false}) scrollContainer: ElementRef<Element>;
@ViewChild('firstRowStart', {static: false}) firstRowStart: ElementRef<Element>;
@ViewChild('firstRowEnd', {static: false}) firstRowEnd: ElementRef<Element>;
@ViewChild('lastRowStart', {static: false}) lastRowStart: ElementRef<Element>;
@ViewChild('lastRowEnd', {static: false}) lastRowEnd: ElementRef<Element>;
}
2 changes: 1 addition & 1 deletion src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class CdkStep implements OnChanges {
_displayDefaultIndicatorType: boolean;

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

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