如何在Angular Material中自定义md-select的弹出菜单?
How to customize md-select's popup menu in Angular Material?
我需要为某些 md-select
的弹出菜单(不是全部)定义一个特殊的 class。但是我不知道该怎么做。
这是典型用法的代码示例,我无法在此处为将出现的菜单容器定义 class。
<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>
其实我想改变弹出菜单的宽度。默认情况下,它受限于 md-select
.
的宽度
您好,请查看以下 plunkr,以下 select 或似乎可以正常工作以影响整个组件
https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview
<style type="text/css">
md-input-container,
md-input-container > * {
width: 100% !important;
}
</style>
编辑:给你,这只会影响select下拉菜单
https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview
<style type="text/css">
._md-select-menu-container
{
width: 100% !important;
}
</style>
最终编辑: 只需将 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>
我需要为某些 md-select
的弹出菜单(不是全部)定义一个特殊的 class。但是我不知道该怎么做。
这是典型用法的代码示例,我无法在此处为将出现的菜单容器定义 class。
<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>
其实我想改变弹出菜单的宽度。默认情况下,它受限于 md-select
.
您好,请查看以下 plunkr,以下 select 或似乎可以正常工作以影响整个组件
https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview
<style type="text/css">
md-input-container,
md-input-container > * {
width: 100% !important;
}
</style>
编辑:给你,这只会影响select下拉菜单
https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview
<style type="text/css">
._md-select-menu-container
{
width: 100% !important;
}
</style>
最终编辑: 只需将 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>