gpt4 book ai didi

Angular 6 MatPaginator 不显示表格的垫选项,也不为下一个按钮和后退按钮设置样式

转载 作者:行者123 更新时间:2023-12-05 05:13:50 24 4
gpt4 key购买 nike

我希望您能帮助确定 select 选项没有出现在 angular 6 mat-paginator 中的原因。以及如何设置返回按钮和下一步按钮的样式。

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

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

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

follow the printout of the problem here

正如我们在打印屏幕上看到的那样,mat-paginator 正在工作,但是当我点击“itens per page”选项时,选择选项不可见(我只有在检查网页元素时才能看到选择选项.

所以我认为这个问题出在某些 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'},
];

list-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%;
}

最佳答案

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

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

样式.css

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

关于Angular 6 MatPaginator 不显示表格的垫选项,也不为下一个按钮和后退按钮设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53156719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com