我想在角度组件中使用cdn中的样式表。样式应仅封装在该组件内。不能使用本机封装模式,因为它不支持。
有什么建议吗?
答案 0 :(得分:0)
我认为在组件模板中有一种很好的方法可以做到这一点。我会说,探索ngAfterViewInit
选项作为大多数外部事物,并且一旦编制了angulat模板,就会放置在组件的lyfe循环中。
@Component({selector: 'my-cmp', template: `...`})
class MyComponent implements AfterViewInit {
ngAfterViewInit() {
// executes after the view is loaded
}
}
如果您使用的是角度cli,则可以在cli文件中配置它们,但我认为您需要将其下载到资产路径并提供路径。我不认为cli会采用cdn路径。
//part of cli configuration
"prefix": "sd",
"styles": [
"../node_modules/bootstrap/scss/bootstrap.scss",
"../node_modules/font-awesome/scss/font-awesome.scss",
"../node_modules/primeng/resources/primeng.min.css",
"../node_modules/primeng/resources/themes/omega/theme.css",
"../node_modules/codemirror/lib/codemirror.css",
"styles.scss"
],