是否可以将全局 CSS 文件添加到 Angular 2?目前,我有许多不同的组件具有相同的按钮样式 - 但每个组件都有自己的 CSS 文件和样式。这对于改变是令人沮丧的。
我在 Stack Overflow 上的某处读到添加:
import { ViewEncapsulation } from '@angular/core'; //add this
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None //add this
})
所以我在根组件中添加了 ViewEncapsulation 行,然后将 CSS 样式添加到根应用程序 CSS (app.component.css) 并从单个组件 CSS 文件中删除了 CSS 样式,但它不起作用。
肯定有办法添加全局 CSS 文件吗?我是否需要向各个组件添加一些内容以使它们访问全局 CSS 文件?
原文由 dandev91 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以简单地在主 html 文件中导入 css。