【问题标题】:Theme angular material pagenator background colour主题角材质分页器背景色
【发布时间】:2019-10-03 23:28:59
【问题描述】:

您好,我正在尝试更改 Angular 项目中 mat-pagenator 控件的背景。

但是,pagenator 似乎总是显示为白色。无论我在应用程序中设置的背景颜色如何。

styles.scss

@import '~@angular/material/theming';
@include mat-core();
$sample-material-app-primary: mat-palette($mat-indigo);
$sample-material-app-accent: mat-palette($mat-pink, A200, A100, A400);
$sample-material-app-warn: mat-palette($mat-red);
$sample-material-app-theme: mat-light-theme($sample-material-app-primary, $sample-material-app-accent, $sample-material-app-warn);
$background: map-get($sample-material-app-theme, background);
$background: map_merge($background, (background: #FF1010));
$theme: map_merge($sample-material-app-theme, (background: $background));
@include angular-material-theme($theme);
@include mat-paginator-theme($theme);
//Just so we can see a background color
html, body { height: 100%; background-color: bisque }

app.component.html

<mat-form-field>
  List length:
  <input matInput [(ngModel)]="length">
</mat-form-field>

<mat-form-field>
  Page size:
  <input matInput [(ngModel)]="pageSize">
</mat-form-field>
<mat-form-field>
  Page size options:
  <input matInput
         [ngModel]="pageSizeOptions"
         (ngModelChange)="setPageSizeOptions($event)">
</mat-form-field>

<mat-paginator [length]="length"
              [pageSize]="pageSize"
              [pageSizeOptions]="pageSizeOptions"
              (page)="pageEvent = $event">
</mat-paginator>

<div *ngIf="pageEvent">
  <h5>Page Change Event Properties</h5>
  <div>List length: {{pageEvent.length}}</div>
  <div>Page size: {{pageEvent.pageSize}}</div>
  <div>Page index: {{pageEvent.pageIndex}}</div>
</div>

结果:

期望的结果是为这个组件(和其他一些)的背景设​​置颜色

我尝试设置背景的方式是基于Angular Material2 theming - how to set app background?

【问题讨论】:

    标签: angular-material2


    【解决方案1】:

    &lt;mat-paginator&gt; 似乎是从卡片继承其背景颜色,而不是从 background 属性。

    &lt;mat-table&gt; 似乎也是如此,因此要设置以下这些的默认样式:(请注意,这是一种难看的颜色,只是为了证明颜色有效)

    @import '~@angular/material/theming';
    @include mat-core();
    $sample-material-app-primary: mat-palette($mat-indigo);
    $sample-material-app-accent: mat-palette($mat-pink, A200, A100, A400);
    $sample-material-app-warn: mat-palette($mat-red);
    $sample-material-app-theme: mat-light-theme($sample-material-app-primary, $sample-material-app-accent, $sample-material-app-warn);
    $background: map-get($sample-material-app-theme, background);
    $bg-color: #FF1010;
    $background: map_merge($background, (background: $bg-color, card: $bg-color, dialog:$bg-color));
    $theme: map_merge($sample-material-app-theme, (background: $background));
    @include angular-material-theme($theme);
    @include mat-paginator-theme($theme);
    //Just so we can see a background color
    html, body { height: 100%; background-color: bisque }
    

    注意我还在其中添加了对话框,因为它也设置为white,并且它可能需要相同的背景颜色。

    【讨论】:

    • 您的回答太珍贵了!我在整个教程网络和其他媒体上都找不到类似的东西。有一件事会有所帮助,您在合并调用中使用一些属性,例如卡片和对话框。你知道在哪里有完整的清单吗?我对工具栏感兴趣。
    • 我现在找到了背景调色板及其所有属性。我需要弄清楚它是如何使用的。
    • 抱歉,Stephane,我通常根本不使用 Angular 或前端。这是在单步执行不同的代码以查看它从何处获取其值后发现的。我不记得步骤了。
    猜你喜欢
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 2018-03-02
    • 2018-10-12
    • 1970-01-01
    • 2018-08-18
    相关资源
    最近更新 更多