根据点击的div元素应用样式表

时间:2016-10-23 19:51:36

标签: angular ionic2

我正在使用Ionic2开发一个应用程序,我有2个样式表, theme1.css theme2.css

这就是我想要的:我有2个div。如果我点击第一个div我会将theme1.css应用到我的应用程序的所有页面,而如果我点击第二个div,所有页面将使用theme2.css。

这是 myPage.html

<div id="theme1" (click)="setTheme('theme1.css')">Apply Theme 1</div>
<div id="theme2" (click)="setTheme('theme2.css')">Apply Theme 2</div>

myPage.ts 我有setTheme方法:

setTheme(stylesheetName){
   // what should I write here??
}

1 个答案:

答案 0 :(得分:0)

<div id="theme1" [ngClass]="theme" (click)="theme = 'theme1'">Apply Theme 1</div>
<div id="theme2" [ngClass]="theme" (click)="theme = 'theme2'">Apply Theme 2</div>

我不知道根据设置的类加载* .css文件。