3

我希望您能帮助确定选择选项未出现在 angular 6 mat-paginator 中的原因。以及如何设置后退按钮和下一个按钮的样式。

我正在尝试按照以下示例进行操作:

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

在上面的示例中,当我从 mat-paginator 单击 mat-option 时,选择选项会出现在表格上方。当我为我的项目复制此示例时,来自 mat-paginator 的选择选项出现在表格下方。我不知道为什么会这样。

在此处按照问题的打印输出

正如我们在打印屏幕中看到的那样,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'},
  ];

列表设备.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%;
 }
4

1 回答 1

2

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

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

样式.css

/* Add application styles & imports to this file! */
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
于 2018-11-05T17:11:13.223 回答