如何在角度组件中使用自定义主题

时间:2019-05-27 12:18:03

标签: angular themes scss-mixins

如何在component.scss中使用自定义主题的原色和强调色?

styles.scss:

@import './themes';

themes.scss:


@import 'app/my.component.theme.scss';

@mixin my-components-theme($theme) {
  @include my-component-theme($theme);
  // ...
}

@mixin set-theme($theme) {
  @include angular-material-theme($theme);
  @include container($theme);
  @include flex-container-column();
  @include my-components-theme($theme);
}

// Theme MY Indigo / Red
$my-theme-primary: mat-palette($mat-indigo);
$my-theme-accent:  mat-palette($mat-red);

$my-light-theme:   mat-light-theme($my-theme-primary, $my-theme-accent);

.my-light-theme {
  @include set-theme($my-light-theme);
}

my.component.scss:

@import '~@angular/material/theming';

@mixin my-component-theme($theme) {
    $primary: map-get($theme, primary);
    $accent: map-get($theme, accent);
    $foreground: map-get($theme, foreground);
    $background: map-get($theme, background);
    .test-class {
        background-color: mat-color($primary, 1) !important;
    }
}

我现在希望在我的组件html中,具有“文本类”类的元素将具有红色背景色。但是该类还没有设置,我无法使用chrome开发工具进行检查。

0 个答案:

没有答案