css - 如何以角度动态加载特定于组件的css样式
问题描述
我正在尝试加载一些特定于组件的 CSS 样式表,这样就不会与项目的其余部分发生冲突。
我的 AppService 中的函数
static loadCSS(url) {
const link = document.createElement('link');
link.href = url;
link.rel = 'stylesheet';
link.type = 'text/css';
const head = document.getElementsByTagName('head')[0];
const style = head.getElementsByTagName('style')[0];
head.insertBefore(link, style);
}
我在所需的组件中有一组样式表
pagesCSS = [
'assets/plugins/bootstrap/css/bootstrap.min.css',
'assets/plugins/font-awesome/css/all.min.css',
'assets/plugins/toastr/toastr.min.css',
'assets/css/lime.min.css',
'assets/css/custom.css'
];
最后
ngOnInit() {
AppService.loadCSS(this.pagesCSS);
}
我收到此错误
The resource from “http://localhost:4200/assets/plugins/bootstrap/css/bootstrap…toastr.min.css,assets/css/lime.min.css,assets/css/custom.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
解决方案
推荐阅读
- android - onActivityCreated 中的 viewLifecycleOwner 为空
- python - 使用 numpy 避免 for 循环以加快计算时间
- c# - 阅读 Dynamics CRM 自定义工作流程中的证书
- javascript - 在不使用 Lodash 的情况下,递归地将对象键从 Snake Case 重命名为 Camel Case
- python - 如何从 py 文件中导入模块
- python - Django/cookiecutter-django 错误:“AttributeError:'Path' 对象没有属性 'endswith''”与 manage.py makemigrations
- ruby-on-rails - 如何在 ActiveRecord::Relation 集合上使用 Elasticsearch?
- spss - 我需要对 2x2 卡方分析进行 Bonferonni 校正吗?
- python - 使用 pytricia、ipaddress 或任何其他库在 Python 中表示 ip 前缀列表
- c# - 构造一个 C# 委托以调用继承的属性 getter