Angular 6 MatPaginator不显示表的mat-option,也不为下一个按钮和后退按钮设置样式

我希望你帮助确定选择选项没有出现在angular 6 mat-paginator中的原因 . 以及如何为“后退”按钮和“下一步”按钮设置样式 .

我正在尝试按照以下示例:

https://stackblitz.com/angular/anvplbamrbj?file=app%2Ftable-pagination-example.html

在上面的例子中,当我从mat-paginator点击mat-option时,select选项出现在表格上方 . 当我为我的项目复制此示例时,mat-paginator中的select选项显示在表格下方 . 我不知道为什么会这样 .

follow the printout of the problem here

正如我们在print sreen中看到的那样,mat-paginator正在工作,但是当我点击“每页itens”选项时“选择选项看起来不可见(当我从网页检查元素时,我只能看到选择选项) .

所以我认为这个问题出现在一些CSS文件中,但我不知道如何修复它?

按照下面的代码:

list-devices.component.html:我只复制并通过stackblitz.com的示例

<div class="mat-elevation-z8">
  <table mat-table [dataSource]="dataSource">
   <!-- Position Column -->
   <ng-container matColumnDef="position">
     <th mat-header-cell *matHeaderCellDef> No. </th>
     <td mat-cell *matCellDef="let element"> {{element.position}} </td>
   </ng-container>

   <!-- Name Column -->
   <ng-container matColumnDef="name">
     <th mat-header-cell *matHeaderCellDef> Name </th>
     <td mat-cell *matCellDef="let element"> {{element.name}} </td>
   </ng-container>

   <!-- Weight Column -->
   <ng-container matColumnDef="weight">
     <th mat-header-cell *matHeaderCellDef> Weight </th>
     <td mat-cell *matCellDef="let element"> {{element.weight}} </td>
   </ng-container>

   <!-- Symbol Column -->
   <ng-container matColumnDef="symbol">
     <th mat-header-cell *matHeaderCellDef> Symbol </th>
     <td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
   </ng-container>

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

  <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>

.ts文件

import { Component, OnInit, ViewChild} from '@angular/core';
 import {MatPaginator, MatTableDataSource} from '@angular/material';

 /**
  * Controller for list devices view
  *
  * @export
  * @class ListDevicesComponent
  * @implements {OnInit}
 */
 @Component({
    selector: 'app-list-device-home',
    templateUrl: './list-devices.component.html',
    styleUrls: ['./list-devices.component.scss']
 })
 export class ListDevicesComponent implements OnInit {
   displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
   dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);

   @ViewChild(MatPaginator) paginator: MatPaginator; 

   ngOnInit() {
     this.dataSource.paginator = this.paginator;
   }
 }


 export interface PeriodicElement {
   name: string;
   position: number;
   weight: number;
   symbol: string;
 }

 const ELEMENT_DATA: PeriodicElement[] = [
    {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
    {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
    {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
    {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
    {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
    {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
    {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
    {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
    {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
    {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
    {position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
    {position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
    {position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
    {position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
    {position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
    {position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
    {position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
    {position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
    {position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
    {position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
  ];

列表devices.component.scss

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

.label{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
}

.mat-paginator-navigation-first {
  background: #11c15b;
}

.label-success{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #11c15b;
}

.label-warning{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #e5e500;
}

.label-danger{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #ff5252;
}

.roow {
  display: flex;
  overflow-x: scroll;
}

.mat-table {
  width: 100%;
}

.td-style {
  font-family: "Roboto", sans-serif;
  font-size: 1.1em;
  color: #455a64;
}

 .th-style {
   font-family: "Roboto", sans-serif;
   font-size: 1em;
   font-weight: bold;
   color: #455a64; 
 }

.table-title-style {
  margin: 20px;
  margin-top: 5px;
  margin-bottom: 0px;
  color: #37474f;
  font-weight: 500;
  position: relative;
  position: sticky;
  font-size: 15px;
  top: 0;
 }

 .mat-header-row {
   position: sticky;
   top: 0;
   background-color: #fff;
 }

.body { 
  font-family: Roboto, Arial, sans-serif;
  margin: 0;
}

.basic-container {
  padding: 30px;
}

.version-info {
  font-size: 8pt;
  float: right;
 }

 /** No CSS for this example */
 ::ng-deep .mat-select-content{
    background-color: red;
    font-size: 1.5em;
 }

 table {
   width: 100%;
 }

回答(1)

2 years ago

请记住按照文档正确安装Angular Material,如下所示:https://material.angular.io/guide/getting-started

对于你的问题,似乎你没有包含影响包含 select 选项的模态框的动画的 BrowsersAnimationModule ,同样,你需要在 styles.css 文件中导入 theme 以使其全局应用,这将是确保您的应用程序中可以使用Angular Material的所有样式 .

styles.css

/* Add application styles & imports to this file! */
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';