如何在Angular Material中自定义md-select的弹出菜单?

spl*_*h27 4 javascript angularjs angular-material

我需要为某些md-select弹出菜单定义一个特殊类(而不是所有).但我不知道该怎么做.

这是典型用法的代码示例,这里我没有可以为将出现的菜单容器定义类的地方.

<md-input-container md-no-float class="md-block defaultInputSelect filterType">
  <md-select ng-model="value.filter_type" md-on-close="viewChanged()">
    <md-option ng-repeat="(key, value) in filterTypes" value="{{value}}">
      {{filterTypesNames[key]}}
    </md-option>
  </md-select>
</md-input-container>
Run Code Online (Sandbox Code Playgroud)

实际上,我想改变弹出菜单的宽度.默认情况下,它受宽度的限制md-select.

joh*_*han 5

您好,请看下面的plunkr,以下选择器似乎工作正常影响整个组件

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

 <style type="text/css">
    md-input-container,
    md-input-container > * {
      width: 100% !important;
    }
  </style>
Run Code Online (Sandbox Code Playgroud)

编辑:在这里,这只会影响选择下拉列表

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

<style type="text/css">
   ._md-select-menu-container
    {
      width: 100% !important;
    }
  </style>
Run Code Online (Sandbox Code Playgroud)

最终编辑:只需将md-container-class ="myclass"指令添加到md-select即可

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

<style type="text/css">
  .myclass {
    width: 100% !important;
  }
</style>

<md-select md-container-class="myclass" ng-model="selectedItem" md-selected-text="getSelectedText()">
  <md-optgroup label="items">
    <md-option ng-value="item" ng-repeat="item in items">Item {{item}}</md-option>
  </md-optgroup>
</md-select>
Run Code Online (Sandbox Code Playgroud)