【问题标题】:Angular custom theme - SassError: $map: null is not a mapAngular 自定义主题 - SassError: $map: null is not a map
【发布时间】:2022-07-13 22:00:17
【问题描述】:

我为我的 Angular 项目创建了以下自定义主题:

@use '@angular/material' as mat;
/* You can add global styles to this file, and also import other style files */


@include mat.core();

$f-brand: (
  50 : #e0f2f1,
  100 : #b3e0db,
  200 : #80cbc4,
  300 : #4db6ac,
  400 : #26a69a,
  500 : #009688,
  600 : #008e80,
  700 : #008375,
  800 : #00796b,
  900 : #006858,
  A100 : #97ffec,
  A200 : #64ffe3,
  A400 : #31ffda,
  A700 : #18ffd5,
  contrast: (
    50 : #000000,
    100 : #000000,
    200 : #000000,
    300 : #000000,
    400 : #ffffff,
    500 : #ffffff,
    600 : #ffffff,
    700 : #ffffff,
    800 : #ffffff,
    900 : #ffffff,
    A100 : #000000,
    A200 : #000000,
    A400 : #000000,
    A700 : #000000,
  )
);

$primary: mat.define-palette($f-brand);

$theme: mat.define-light-theme($primary);

@include mat.all-component-themes($theme);

我还将自定义主题添加到我的常规 styles.css 文件中,但是当我运行“ng serve”时出现以下错误:

SassError: $map: null is not a map.
  ╷
9 │   $foreground-base: map.get($foreground, base);
  │                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  node_modules\@angular\material\core\ripple\_ripple-theme.scss 9:21  color()
  node_modules\@angular\material\core\ripple\_ripple-theme.scss 30:7  @content
  node_modules\@angular\material\core\theming\_theming.scss 376:3     private-check-duplicate-theme-styles()
  node_modules\@angular\material\core\ripple\_ripple-theme.scss 27:3  theme()
  node_modules\@angular\material\core\_core-theme.scss 48:5           @content
  node_modules\@angular\material\core\theming\_theming.scss 376:3     private-check-duplicate-theme-styles()
  node_modules\@angular\material\core\_core-theme.scss 47:3           theme()
  node_modules\@angular\material\core\theming\_all-theme.scss 43:5    @content
  node_modules\@angular\material\core\theming\_theming.scss 376:3     private-check-duplicate-theme-styles()
  node_modules\@angular\material\core\theming\_all-theme.scss 42:3    all-component-themes()
  src\styles-f-theme.scss 44:1                                        root stylesheet

通过网络搜索,我发现“map.get”现在似乎是“map-get”。不幸的是,我不知道如何解决这个问题。

我的项目中使用的 Angular 版本是“14.0.5”,Angular Material 版本是“14.0.4”,

【问题讨论】:

    标签: css angular sass


    【解决方案1】:

    你有这个错误,因为要构建一个主题,需要 2 个调色板:主要和重音。

    添加新调色板或将您的主要设置为重音:

    $theme: mat.define-light-theme($primary, $primary);
    

    【讨论】:

    • 哦,我不知道这一点。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 2021-02-27
    • 2021-11-10
    相关资源
    最近更新 更多