There are 2 css files : src/assets/style1.css and src/assets/style2.css
Step - 1 : Add a link with an id inside head of index.html file
<html>
<head>
<link href="" id="mycss" rel="stylesheet">
</head>
<body>
<my-app></my-app>
</body>
</html>
Step - 2 : Use following typescript and modify with your own desired logic
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
files = ["assets/style1.css","assets/style2.css"]
constructor(@Inject(DOCUMENT) private document) {}
toggle() {
var oldlink = this.document.getElementById("mycss");
var newlink = this.document.createElement("link");
newlink.setAttribute("rel", "stylesheet");
newlink.setAttribute("type", "text/css");
newlink.setAttribute("href", this.files[1]);
this.document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
}
}