Angular Material2 md-select dropdown appears at bottom of the page

给你一囗甜甜゛ 提交于 2019-12-01 18:41:22

I had the same problem. I resolved it by importing the material theme:

@import '~@angular/material/core/theming/prebuilt/[one-of-the-themes].css';

in my main styleseet.

If you are installing angular material to your angular cli project then your themes would be in node_modules/@angular/material/prebuilt-themes/

so import link would be something like shown below

@import "~@angular/material/prebuilt-themes/deeppurple-amber.css"

We should add the above line to our angular-cli application's styles.css file. Here deeppurple-amber.css is one of the prebuilt theme angular material is offering us. Most of the built-in components like md-select won't be working as expected if this import has not done properly.

Happy Coding :)

I had the same problem but with the datepicker control. It was not popping up below the text box, but at the bottom of the page.

I tried what the other answer recommended and importing a theme into the styles.css file:

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

and that didn't work for me by itself, but it was a step in the right direction.

But I also needed to make a couple changes to the app.module.ts file:

Add this to the imports:

import {OverlayContainer} from '@angular/material';

And change the app module class declaration:

export class AppModule {
constructor(overlayContainer: OverlayContainer) {
    overlayContainer.themeClass = 'unicorn-dark-theme';
}

You can find more info on this here:

https://material.angular.io/guide/theming

After doing all that, the date picker started working for me and not popping up at the bottom of the page when clicked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!