打开角度材质选择时禁用滚动

Tob*_*ann 3 angular-material2

默认情况下,选择角材料的dropwon将允许页面滚动并相应地重新定位自身。

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?

Wil*_*ell 6

由于垫选组件通过DI注入了策略,因此您可以在组件中(或您希望的话)在模块级别提供替代方案。

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] }
]
Run Code Online (Sandbox Code Playgroud)

-

叠砖