2017-12-27 213 views
1

我正在使用angular 5.我的模塊我正在使用單張1.2.0。角。如何從node_modules導入css

在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); 
} 

所以,我需要訪問leaflet.css其相對的路線,我的嘗試:

@Component({ 
    selector: 'myComponent', 
    template:`<div id="myId" class="myClass"></div>`, 
    styleUrls: ['./myComponent.component.scss','/../../../../node_modules/leaflet/dist/leaflet.css'], 
}) 

的文件夾結構:

--project_folder 
    --node_modules 
    --leaflet 
     --dist 
      --leaflet.css 
    --src 
    --app 
     --myComponentParent 
     --myComponent 
      --myComponent.component.ts 
      --myComponent.component.scss 
      --myComponent.component.html 

可以參考我夾了SRC的?我該怎麼做?

回答

4

如果您正在使用角CLI,您需要將單張CSS文件添加到樣式數組中包含。 angular-cli.json並刪除其他地方的css導入

"styles": [ 
     "styles.css", 
     "../node_modules/leaflet/dist/leaflet.css", 
] 
3

無需像這樣添加。在angular-cli.json文件中添加樣式標籤與腳本路徑

"styles": [ 
     "../node_modules/leaflet/dist/leaflet.css", 
] 

從組件刪除腳本

​​