【问题标题】:Angular Material Dropdown inside Bootstrap ModalBootstrap 模态中的 Angular Material Dropdown
【发布时间】:2020-07-23 18:13:54
【问题描述】:

我有一个 Angular 5 应用程序,它必须在 Bootstrap 模态中使用 Angular Material 的 mat-select。问题是下拉选项出现在模式后面。我的代码如下所示:

<mat-form-field class="mdb-form-field form-adjustments">
    <mat-select placeholder="What fruit are you looking for?" [formControl]="fruitType" [(ngModel)]="defaultFruitType">
        <mat-option *ngFor="let fruitType of fruitTypes" [value]="fruitType">{{ fruitType }}
        </mat-option>
    </mat-select>
</mat-form-field>

我知道我应该使用 z-index 将 Angular Material 的选择选项放在前面。但问题是上什么课?我尝试将它应用于 Angular Material 的多个类,但无济于事。以下所有方法均失败:

body div.cdk-overlay-container {
  z-index: 99999;
}

/deep/ .cdk-overlay-pane {
  z-index: 99999 !important;
}

/deep/ .cdk-global-overlay-wrapper, .cdk-overlay-container {
  z-index: 99999 !important;
}

.mat-select-menu-container {
  z-index: 99999 !important;
}

.mat-dialog-container {
  z-index: 99999;
}

/deep/ .mat-select-panel {
  z-index: 99999 !important;
}

/deep/ .mat-primary {
  z-index: 99999 !important;
}

有谁知道我必须在哪一类 Angular Material 上应用 z-index 才能将选择选项置于模态框的最前面?

谢谢!

【问题讨论】:

    标签: angular less angular-material2 angular-material-5


    【解决方案1】:

    我在使用 Angular Material 6/Bootstrap 4 时遇到了同样的问题。我在 styles.scss 文件中使用以下样式解决了这个问题 -

    .cdk-global-overlay-wrapper {
         z-index: 1000;
    }
    

    【讨论】:

    • 我必须在其中添加!important,但这有效。我浪费了几个小时寻找解决方案。谢谢!
    【解决方案2】:

    我尝试了许多破解方法,但只有一个对我有用:

    .cdk-overlay-container {
      z-index: 9999 !important;
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 2017-11-01
      • 2023-03-03
      • 2016-03-04
      • 2015-11-22
      • 2016-07-09
      相关资源
      最近更新 更多