You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14升级至15后应用报错:mat-core混入传参错误

Angular 14升级至15后mat-core传参报错解决方案

问题原因

Angular Material 15对mat-core混入做了破坏性变更:该混入不再接受任何参数,而你代码里仍在调用@include mat-core($fontConfig);,触发了参数数量不匹配的Sass错误。

解决步骤

  1. 修改mat-core调用
    打开src/material.theme.scss,找到第147行的@include mat-core($fontConfig);,将其改为不带参数的形式:

    @include mat-core;
    
  2. 迁移字体配置(如果需要)
    若原本通过$fontConfig配置字体,需改用Angular Material 15的主题配置方式,将字体设置合并到主题定义中:

    // 示例:自定义字体栈并应用到主题
    $custom-typography: mat.define-typography-config(
      font-family: '"Roboto", "Helvetica Neue", sans-serif'
      // 可额外配置其他字体相关属性,比如字体大小、行高
    );
    
    $my-theme: mat.define-light-theme((
      color: ..., // 你的主题颜色配置
      typography: $custom-typography
    ));
    

注意事项

升级Angular版本时,务必同步关注Angular Material的官方变更说明,重点留意主题、排版相关的API变动,避免类似的兼容性问题。

内容的提问来源于stack exchange,提问作者Hamza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 18:25:17