简体   繁体   English

如何添加open-iconic到angular 2项目

[英]How to add open-iconic to angular 2 project

I create an angular project, I added bootstrap to it but I noticed that the new version of bootstrap(version 4) doesn't have an icon library, so I install it using: 我创建了一个角度项目,我添加了bootstrap但是我注意到新版本的bootstrap(版本4)没有图标库,所以我使用以下命令安装它:

npm install open-iconic

But I don't know how to add it to my project, according to the web page, I need to add this two lines: 但我不知道如何将它添加到我的项目中,根据网页,我需要添加以下两行:

<link href="/open-iconic/font/css/open-iconic-bootstrap.css" rel="stylesheet">
<span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span>

So I trying adding the path of the css on the angular-cli.json but my button is not showing the icon, can someone help me with this?, 所以我尝试在angular-cli.json上添加css的路径但是我的按钮没有显示图标,有人可以帮我这个吗?

Thanks in advance. 提前致谢。

将“../node_modules/open-iconic/font/css/open-iconic-bootstrap.min.css”添加到.angular-cli.json文件中的“styles”选项。

In case that some one is coming to this question and the solution above will not work for him properly and you have the error when you try to use scss include in your styles.scss : 如果有些人会来这个问题,并解决上述不会为他的正常工作,你有错误,当您尝试使用SCSS包括在styles.scss

ERROR in ./src/styles.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js./src/styles.scss) (Emitted value instead of an instance of Error) CssSyntaxError: node_modules\\open-iconic\\font\\css\\open-iconic-bootstrap.scss: Can't resolve '../node_modules/open-iconic/font/css/open-iconic.eot' in 'src'

it happens because the relative path in the file open-iconic-bootstrap points to $icon-font-path: '../fonts/' !default; 这是因为open-iconic-bootstrap文件中的相对路径指向$icon-font-path: '../fonts/' !default; and the sass compiler thinks that the root path is src/app (the angular root path) 并且sass编译器认为根路径是src/app (角度根路径)

the solution before the @import statement in styles.scss override $icon-font-path variable to point the right path: styles.scss @import语句之前的解决方案覆盖$icon-font-path变量以指向正确的路径:

$icon-font-path: '~open-iconic/font/fonts/';
@import "~open-iconic/font/css/open-iconic-bootstrap.scss";

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

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