Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to apply custom Angular theme to all elements?

I have made a custom Angular theme ‘my-theme.scss’ and included it in the angular.json file. It works fine with all Angular-Elements, but to some HTML-Elements within Angular Components it does not apply.

Example:

<mat-card class="example-card">
            <mat-card-header>
                <mat-card-title-group>
                    <mat-card-title>Java</mat-card-title>
                    <img mat-card-sm-image src="../../../assets/java.png">
                </mat-card-title-group>
            </mat-card-header>
            <mat-card-content>
                <p>
                Put a list here.
                </p>
            </mat-card-content>
</mat-card>

The custom typography of my ‘my-theme.scss’ will apply to the title of this card:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Screenshot-from-2023-04-18-18-17-01.png

But it won’t apply to the anything within the mat-card-content for example.
Screenshot-from-2023-04-18-18-22-47.png

Why is this and how can I fix it?

>Solution :

In your styles.scss, you will ned to apply your font to your body:
(Working example with Angular / Material 15)

@use "@angular/material" as material;

$custom-typography: material.define-typography-config(
  $font-family: "'Open Sans', sans-serif",
);
@include material.typography-hierarchy($custom-typography);

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Open Sans", sans-serif; // <-- Add this
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading