diff --git a/src/lib/select/select-module.ts b/src/lib/select/select-module.ts index 64c2634a4140..399981d84e77 100644 --- a/src/lib/select/select-module.ts +++ b/src/lib/select/select-module.ts @@ -5,12 +5,13 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {NgModule} from '@angular/core'; + +import {OverlayModule} from '@angular/cdk/overlay'; import {CommonModule} from '@angular/common'; -import {MatSelect, MatSelectTrigger} from './select'; +import {NgModule} from '@angular/core'; import {MatCommonModule, MatOptionModule} from '@angular/material/core'; -import {OverlayModule} from '@angular/cdk/overlay'; import {MatFormFieldModule} from '@angular/material/form-field'; +import {MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MatSelect, MatSelectTrigger} from './select'; @NgModule({ @@ -22,5 +23,6 @@ import {MatFormFieldModule} from '@angular/material/form-field'; ], exports: [MatFormFieldModule, MatSelect, MatSelectTrigger, MatOptionModule, MatCommonModule], declarations: [MatSelect, MatSelectTrigger], + providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER] }) export class MatSelectModule {} diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index fbed800d7ecb..11866e13f3f9 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -23,10 +23,10 @@ import { import { CdkConnectedOverlay, Overlay, + RepositionScrollStrategy, ScrollStrategy, ViewportRuler, } from '@angular/cdk/overlay'; -import {filter, take, map, switchMap, takeUntil, startWith} from 'rxjs/operators'; import { AfterContentInit, Attribute, @@ -40,7 +40,6 @@ import { ElementRef, EventEmitter, Inject, - inject, InjectionToken, Input, isDevMode, @@ -75,7 +74,8 @@ import { mixinTabIndex, } from '@angular/material/core'; import {MatFormField, MatFormFieldControl} from '@angular/material/form-field'; -import {defer, Subject, merge, Observable} from 'rxjs'; +import {defer, merge, Observable, Subject} from 'rxjs'; +import {filter, map, startWith, switchMap, take, takeUntil} from 'rxjs/operators'; import {matSelectAnimations} from './select-animations'; import { getMatSelectDynamicMultipleError, @@ -122,13 +122,20 @@ export const SELECT_PANEL_VIEWPORT_PADDING = 8; /** Injection token that determines the scroll handling while a select is open. */ export const MAT_SELECT_SCROLL_STRATEGY = - new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy', { - providedIn: 'root', - factory: () => { - const overlay = inject(Overlay); - return () => overlay.scrollStrategies.reposition(); - } - }); + new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy'); + +/** @docs-private */ +export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay): + () => RepositionScrollStrategy { + return () => overlay.scrollStrategies.reposition(); +} + +/** @docs-private */ +export const MAT_SELECT_SCROLL_STRATEGY_PROVIDER = { + provide: MAT_SELECT_SCROLL_STRATEGY, + deps: [Overlay], + useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY, +}; /** Change event object that is emitted when the select value has changed. */ export class MatSelectChange {