Angular2:如何从node_modules导入样式表? [英] Angular2: How to import a stylesheet from node_modules?

查看:134
本文介绍了Angular2:如何从node_modules导入样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题::在我的Angular2(4.0)应用中,如何从node_modules中的模块导入样式表(css)?

Question: In my Angular2 (4.0) app, how can I import stylesheets (css) from a module in node_modules?

我在这里有一个模块:

node_modules/@swimlane/ngx-datatable

我要导入此样式表:

node_modules/@swimlane/ngx-datatable/release/index.css

我尝试了以下方法,但没有运气:

在我的组件中自己的scss文件:

In my components own scss file:

@import '~@swimlane/ngx-datatable/release/index.css';

在我的组件中:

@Component({
  encapsulation: ViewEncapsulation.None,
  selector: 'site_table',
  template: require('./site_table.html'),
  styleUrls: ['./site_table.scss', '@swimlane/ngx-datatable/release/index.css']
})

推荐答案

由于您已经在使用SCSS,因此在./site_table.scss中将其导入为

Because you're already using SCSS, in your ./site_table.scss import it like so

@import "~swimlane/ngx-datatable/release/index";

注意:请勿添加扩展名.

Note: do not add the extension.

它将从节点包中导入样式表.这样做对我很有帮助,希望它也对您有用.这样,您只需要在组件中使用单个样式表即可,它看起来会更干净.

It will import stylesheet from node package. That served my well, hope it will do for you too. That way you just have to use single stylesheet in your component and it will look cleaner.

这篇关于Angular2:如何从node_modules导入样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆