By default the select-dropwon of angular-material will allow the page to scroll and reposition itself accordingly.
On the original page of the material-documentation the select-dropdown shows a differetn behaviour: it blocks scrolling when openend:
https://material.angular.io/components/select/overview
How can I achieve this behaviour? I did not find any options or switch to disable scrolling when the select is clicked
EDIT: I did find that there is a thing called "mat-select-scroll-strategy", but it is not documented anywhere. Can anybody give me a hint how to use this?
Since the mat-select component injects a strategy through DI, you can provide an alternative in your component (or at the module level if you wish).
import { MAT_SELECT_SCROLL_STRATEGY } from '@angular/material';
import { Overlay, BlockScrollStrategy } from '@angular/cdk/overlay';
export function scrollFactory(overlay: Overlay): () => BlockScrollStrategy {
return () => overlay.scrollStrategies.block();
}
// ...
providers: [
{ provide: MAT_SELECT_SCROLL_STRATEGY, useFactory: scrollFactory, deps: [Overlay] }
]
--
来源:https://stackoverflow.com/questions/46888635/disable-scrolling-when-angular-material-select-is-open