如何仅更改所有材质组件 Angular 15 的字体系列?

csy*_*ski 1 angular-material angular

好吧,为什么改变字体系列是最痛苦的事情,但同时却没有很好的记录。我只需要更改应用程序材料组件的字体系列。如何做到这一点?我见过这个: https: //material.angular.io/guide/typography 但是你真的需要重新定义所有内容只是为了更改字体系列吗?

小智 5

在全局 style.scss 上进行此更改

@use '@angular/material' as mat;

$open-sans-typography: mat.define-typography-config($font-family: '"Open Sans", sans-serif');

@include mat.typography-hierarchy($open-sans-typography);

$app-theme: mat.define-light-theme((
  typography: $open-sans-typography
));

@include mat.all-component-themes($app-theme);
Run Code Online (Sandbox Code Playgroud)

当我尝试用 Open Sans 替换全局字体时,这解决了我的问题