[英]angular. How to import css from node_modules
I'm using angular 5. Im my module I'm using leaflet 1.2.0. 我正在使用角度5.我的模块我正在使用传单1.2.0。
In leaflet.css I have trouble with images, for example, some css lines: 在leaflet.css中我遇到图像问题,例如,一些css行:
.leaflet-retina .leaflet-control-layers-toggle {
background-image: url(/assets/images/leaflet/layers-2x.png);
background-size: 26px 26px;
}
/* Default icon URLs */
.leaflet-default-icon-path {
background-image: url(/assets/images/leaflet/marker-icon.png);
}
So, I need to access leaflet.css to its relative route, what I tried: 所以,我需要访问leaflet.css到它的相对路径,我尝试了:
@Component({
selector: 'myComponent',
template:`<div id="myId" class="myClass"></div>`,
styleUrls: ['./myComponent.component.scss','/../../../../node_modules/leaflet/dist/leaflet.css'],
})
The folder structure: 文件夹结构:
--project_folder
--node_modules
--leaflet
--dist
--leaflet.css
--src
--app
--myComponentParent
--myComponent
--myComponent.component.ts
--myComponent.component.scss
--myComponent.component.html
Can I refer to folder out of src? 我可以参考src中的文件夹吗? How can I do it?
我该怎么做?
If you are using Angular CLI, you will need to add the Leaflet CSS file to the styles array contained in . 如果您使用的是Angular CLI,则需要将Leaflet CSS文件添加到包含在其中的样式数组中。
angular-cli.json
and remove css import from other places angular-cli.json
并从其他地方删除css导入
"styles": [
"styles.css",
"../node_modules/leaflet/dist/leaflet.css",
]
No need to add like this. 无需像这样添加。 in your
angular-cli.json
file add style tag with the script path 在
angular-cli.json
文件中,使用脚本路径添加样式标记
"styles": [
"../node_modules/leaflet/dist/leaflet.css",
]
remove the script from your component 从组件中删除脚本
styleUrls: ['./myComponent.component.scss'],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.