You can create a compononent for each font-style, and import in your root component conforms the condition:
Example for Roboto.
Component
Note: encapsulation: ViewEncapsulation.None
is very important for this case.
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-font-roboto',
templateUrl: './font-roboto.component.html',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./font-roboto.component.scss']
})
export class FontRobotoComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
SCSS
@font-face {
font-family: 'Roboto';
src: url("/assets/fonts/Roboto/Roboto-Regular.eot");
/* IE9 Compat Modes */
src: url("/assets/fonts/Roboto/Roboto-Regular.eot?#iefix") format('embedded-opentype'), /* IE6-IE8 */
url('/assets/fonts/Roboto/Roboto-Regular.ttf') format('truetype'), /* Safari, Android, iOS */
}
@font-face {
font-family: 'RobotoBold';
src: url("/assets/fonts/Roboto/Roboto-Bold.eot");
/* IE9 Compat Modes */
src: url("/assets/fonts/Roboto/Roboto-Bold.eot?#iefix") format('embedded-opentype'), /* IE6-IE8 */
url('/assets/fonts/Roboto/Roboto-Bold.ttf') format('truetype'), /* Safari, Android, iOS */
}
body {
font-family: 'Roboto', sans-serif;
}
Root component logic
Template [HTML]
<div [ngSwitch]="fontType">
<app-font-roboto *ngSwitchCase="'Roboto'"></app-font-roboto>
</div>
Component
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
fontType: string;
ngOnInit(): void {
this.fontType = 'Roboto';
}
}
Just add your application logic to get the current font and add new nodes in switch for each font styles that you need.