Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Google fonts library with angular 6?

I added Google fonts link in styles.scss file of Angular project.

@import url('https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700');

But It already works with Angular CLI command ng serve, but, trying to build up command ng build --prod --base-href deployed the project. Then noticed the issues.

The issue is it "didn't work with import google font".

I'm researching for this issue on google. but I didn't find a good solution.

I want to know how do apply the google font in an angular project?

like image 531
RedAnz Avatar asked Aug 04 '18 15:08

RedAnz


People also ask

How do I use Google Fonts in angular 6?

import google fonts in angularfonts include in the style tag of the head section of index. html . In the styles, CSS @import is used to include external CSS files. It imports google fonts into the angular application and provides faster performance compared to the link approach.


2 Answers

This is best way to use google font locally with angular 2,4,5,6,7 and more, First Download Google Font and this in inside the assets folder and use it is as per your requirement.

In angular.json call this in src/assets

"assets": [
    "src/assets"
 ],

In css file add this font-face in top

@font-face {
  font-family: 'Montserrat';
  src: url(/assets/Montserrat/Montserrat-Light.ttf) format("truetype");
  font-weight:300;
}

At Last use it as per your requirement like

body{
 font-family: 'Montserrat', sans-serif;
}
like image 167
codeuix Avatar answered Sep 18 '22 17:09

codeuix


If you want to include your own version of Roboto font from google inside your angular app

npm install roboto-fontface

then inside your angular.json file add the font file in the styles list like this

"styles": [              
          "node_modules/roboto-fontface/css/roboto/roboto-fontface.css"
        ],
like image 26
Mustafa Avatar answered Sep 20 '22 17:09

Mustafa