如何在Angular 2中更改应用程序范围的css?
在我的应用程序中,我有不同的CSS文件,如fire.CSS、lake.CSS,每个文件都为完整的应用程序提供了不同的外观 目前,我只使用1个文件main.css实现,并将该文件添加到如何在Angular 2中更改应用程序范围的css?,css,angular,stylesheet,angular2-template,angular2-directives,Css,Angular,Stylesheet,Angular2 Template,Angular2 Directives,在我的应用程序中,我有不同的CSS文件,如fire.CSS、lake.CSS,每个文件都为完整的应用程序提供了不同的外观 目前,我只使用1个文件main.css实现,并将该文件添加到index.html <link rel="stylesheet" href="resources/styles/main.css"> <link rel="stylesheet" href="resources/styles/themes.css"> <link rel="styl
index.html
<link rel="stylesheet" href="resources/styles/main.css">
<link rel="stylesheet" href="resources/styles/themes.css">
<link rel="stylesheet" href="resources/styles/common.css">
<link rel="stylesheet" href="resources/styles/plugins.css">
现在,我想在用户从下拉列表中选择时动态地更改它
我的想法是:
将所有css文件复制到应用程序文件夹并在其中添加主题文件夹结构不正确 app
|----app.component.ts
|-----app.routes.ts
|-----main.css
|-----lake.css
|-----登录
|-----其他组件…
我在app.components.ts中将css添加到styleURL中,app.components现在是
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
selector: 'workshop-app',
template: `
<body>
<router-outlet></router-outlet>
</body>
`,
directives : [ ROUTER_DIRECTIVES ],
styleUrls : ['app/lake.css']
})
export class AppComponent { }
从'@angular/core'导入{Component};
从“@angular/ROUTER”导入{ROUTER_DIRECTIVES}”;
@组成部分({
选择器:“车间应用程序”,
模板:`
`,
指令:[路由器指令],
样式URL:['app/lake.css']
})
导出类AppComponent{}
Lake.css文件中的内容将添加到应用程序下的样式标记中,但不会在应用程序中进行更改。将其添加到app.component.html
<head>
<link id="theme" rel='stylesheet' href='demo.css'>
</head>
在Angular.json文件中使用文件替换:
"configurations": {
"yourproject": { ... },
"staging": {
"fileReplacements": [
{
"replace": "src/styles.css",
"with": "src/new-styles.css"
}
]
}
}
你可以在这里更好地查看用法:也许这会有帮助。回答得好!!!项目提交时没有此功能,我将在业余时间尝试。很高兴能帮助您,希望您luckhe在用户输入某些操作时请求以友好方式更改样式,而不是在构建时
"configurations": {
"yourproject": { ... },
"staging": {
"fileReplacements": [
{
"replace": "src/styles.css",
"with": "src/new-styles.css"
}
]
}
}