【问题标题】:Working with mat dialog and bootstrap sticky top class使用 mat dialog 和 bootstrap sticky top 类
【发布时间】:2022-01-28 04:10:09
【问题描述】:

我面临的问题是,每次单击删除条目时,它都会出现一个垫子对话框,并且背景中的其他所有内容都变灰,但是,我面临的行为是,一旦我尝试删除对话框出现一个条目,但粘性顶部(在本例中为标题)没有变灰。日志组件位于详细信息组件中,因此当对话框出现时,除了粘性之外的所有内容都是灰色的。代码如下所示。有谁知道如何处理这种情况或为什么会出现这种行为?

使用:Angular Material 版本12.2.13。引导版本5.1

log.component.html

<div class="row mx-auto">
      <table mat-table [dataSource]="LogSource" class="mat-elevation-z8 orange">
        
        //...other tables are go here

        <ng-container matColumnDef="Delete">
          <th mat-header-cell *matHeaderCellDef></th>
          <td mat-cell *matCellDef="let element" (click)="deleteEntry(12)">
            <button class="btn btn-danger">
              <i class="bi bi-x"></i>
            </button>
          </td>
        </ng-container>

        <tr mat-header-row *matHeaderRowDef="displayColumns"></tr>
        <tr
          mat-row
          *matRowDef="let row; columns: displayColumns"
        ></tr>
      </table>

log.component.ts

import { Component, OnInit} from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { LogMessageComponent } from 'src/app/dialogs/log-message/log-message.component';

@Component({
  selector: 'app-log',
  templateUrl: './log.component.html',
  styleUrls: ['./log.component.scss'],
})
export class LogComponent implements OnInit {

  displayContactLogColumns = [
    'CreatedDateTime',
    'CreatedByUser',
    'ContactType',
    'Study',
    'Outcome',
    'OutcomeDetails',
    'Notes',
    'Delete',
  ];
  LogSource: any[];
  errorMessage: string;

  constructor(
    public dialog: MatDialog
  ) {
    this.LogSource = [];
    this.errorMessage = ''
  }

  deleteLog(Id: number) {

    if (deleteLog !== -1) {
      //I'm forcing a delete for now
    } else {
      const errorMessage = `Could not find log with id of ${Id}`;
      this.dialog.open(LogMessageComponent);

      throw new Error(errorMessage);
    }
  }
}

sticky.component.ts 这就是粘性所在。

<section id="details" class="container">
  <!-- SUMMARY -->
  <header id="demo" class="mt-3 sticky-top bg-body">
    <div class="row">
      //Some code goes here
    </div>
  </header>
</section>

【问题讨论】:

    标签: html css angular angular-material bootstrap-5


    【解决方案1】:

    我以前无法测试它,但如果你制作一个 css 类 让整个屏幕“变灰”,也许你可以解决你的问题,例如:

    .hideFullScreen {
      background:grey;
      position:absolute;
      top:0px;
      right:0px;
      bottom:0px;
      left:0px;
    }
    

    然后您为您的对话框制作一个材质对话框配置,并将“hideFullScreen”类 css 添加到其中:

    if (deleteContact !== -1) {
          //I'm forcing a delete for now
        } else {
          const errorMessage = `Could not find log with id of ${Id}`;
          const dialogConfig = new MatDialogConfig();
          dialogConfig.panelClass = 'hideFullScreen';      
          this.dialog.open( ContactLogMessageComponent, dialogConfig );
    
          throw new Error(errorMessage);
        }
      }
    

    【讨论】:

    • 不幸的是,这对我不起作用
    • 好的,所以我删除了``` top:0px;右:0px;底部:0px; left:0px;``` 我还将.panelClass 更改为.backDropClass。我可以看到所做的更改,但是,粘性仍然通过背景出现。我希望整个背景都“变灰”。不过,这让我有所收获。谢谢!
    • 我很高兴它在某种程度上有所帮助。
    • 好的,所以我找到了一种方法,可以让 bootstrap 置顶以使用角材料的 mat-dialog。 .sticky-top 的 z-index 似乎为 1020,所以我所做的就是用高于 1020 的 z-index 覆盖 .cdk-overlay-container。这对我有用。希望这对未来的每个人都有效。
    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2018-12-20
    • 2018-02-09
    • 1970-01-01
    • 2019-03-05
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多