You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ngx-bootstrap Modal中mat-select选项显示在模态框后方的问题求助

Fixing mat-select Options Showing Behind ngx-bootstrap Modal

Hey there, I've run into this exact issue before—it's all about z-index stacking order! The problem is that ngx-bootstrap's modal has a higher default z-index than Angular Material's mat-select dropdown overlay, so the options end up hidden behind the modal.

First, let's clear up a useless line in your code: the style attribute on your <ng-template> doesn't do anything here. <ng-template> is just a template placeholder and doesn't render into the actual DOM, so those styles won't apply to the modal content at all.

Here's how to fix this properly:

Solution 1: Adjust the CDK Overlay Z-Index Globally

Angular Material uses the cdk-overlay-container to render dropdowns and other floating elements. We just need to make sure its z-index is higher than ngx-bootstrap's modal (which defaults to 1040).

Add this to your global styles file (usually styles.scss or styles.css at the root of your project):

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

If you want to avoid using !important (a good practice when possible), you can target it only when a modal is open:

.modal-open .cdk-overlay-container {
  z-index: 1050;
}

Solution 2: Target Specific Modals (Optional)

If you only need this fix for one specific modal, you can add a custom class when opening the modal, then adjust the overlay z-index for that scenario.

When opening the modal in your component code:

this.modalService.show(this.editTemplate, {
  class: 'custom-select-modal'
});

Then add this to your global styles:

.custom-select-modal ~ .cdk-overlay-container {
  z-index: 1050;
}

Updated Template Code

Remove the unnecessary style from your <ng-template> since it doesn't work:

<ng-template #editTemplate>
  <mat-form-field>
    <mat-select multiple placeholder="Multiple Cities" [(ngModel)]="currentCity" name="Paris" ariaLabel="cities[0]">
      <mat-option *ngFor="let city of cities" [value]="city.value">
        {{ city.viewValue }}
      </mat-option>
    </mat-select>
  </mat-form-field>
</ng-template>

After applying one of these solutions, your mat-select dropdown options should render on top of the ngx-bootstrap modal instead of behind it.

内容的提问来源于stack exchange,提问作者Hassan Amjad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:45:26