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?
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.
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;
}
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"
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With