繁体   English   中英

在angular 2组件中使用来自CDN的样式表

[英]Use stylesheet from cdn inside angular 2 component

我想使用角度组件内cdn的样式表。 样式应仅封装在该组件内。 无法使用本机封装模式,因为它不支持。

有什么建议吗?

我认为您无法在组件模板中实现此目的。 我会说要探索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"
  ],

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM