How do I use a font other than Roboto in Angular 18 and Material 3

Discussão em 'Angular' iniciado por Roger i, Novembro 13, 2024.

  1. Roger i

    Roger i Guest

    I am just starting on angular 3 and have the bugs worked out. However, I am having an issue trying to get different fonts and typography to work properly

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>StateLineRodz</title>
    <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Muli:400,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    </head>
    <body class="mat-typography mat-app-background">
    <app-component-test></app-component-test>
    <app-root></app-root>
    </body>
    </html>


    My style.scss


    @use '@angular/material' as mat;

    $theme: mat.define-theme(
    (
    color: (
    theme-type: light,
    primary: mat.$blue-palette,
    tertiary: mat.$magenta-palette,
    ),
    )
    );

    html,body {
    font-family: Roboto, 'Helvetica Neue', sans-serif;
    margin: 0;
    padding: 30px;
    height: 100%;
    @include mat.all-component-themes($theme);
    }



    :host {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    }

    angular.json


    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
    "stateLineRodz": {
    "projectType": "application",
    "schematics": {
    "@schematics/angular:component": {
    "style": "scss"
    }
    },
    "root": "",
    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
    "outputPath": "dist/state-line-rodz",
    "index": "src/index.html",
    "browser": "src/main.ts",
    "polyfills": [
    "zone.js"
    ],
    "tsConfig": "tsconfig.app.json",
    "inlineStyleLanguage": "scss",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": [
    "src/styles.scss",
    "src/m3-theme.scss"
    ],
    "scripts": []
    },
    "configurations": {
    "production": {
    "budgets": [
    {
    "type": "initial",
    "maximumWarning": "500kB",
    "maximumError": "1MB"
    },
    {
    "type": "anyComponentStyle",
    "maximumWarning": "2kB",
    "maximumError": "4kB"
    }
    ],
    "outputHashing": "all"
    },
    "development": {
    "optimization": false,
    "extractLicenses": false,
    "sourceMap": true
    }
    },
    "defaultConfiguration": "production"
    },
    "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "configurations": {
    "production": {
    "buildTarget": "stateLineRodz:build:production"
    },
    "development": {
    "buildTarget": "stateLineRodz:build:development"
    }
    },
    "defaultConfiguration": "development"
    },
    "extract-i18n": {
    "builder": "@angular-devkit/build-angular:extract-i18n"
    },
    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "polyfills": [
    "zone.js",
    "zone.js/testing"
    ],
    "tsConfig": "tsconfig.spec.json",
    "inlineStyleLanguage": "scss",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": [
    "src/styles.scss",
    "src/m3-theme.scss"
    ],
    "scripts": []
    }
    }
    }
    }
    },
    "cli": {
    "analytics": false
    }
    }

    When I load the page, I always get the same font I've tried to load the page with fonts that dont exist and no luck, just compiles and say "OK"

    I have no more clues on guessing this stuff.

    Continue reading...

Compartilhe esta Página