2016-12-05 108 views
0

我正在使用angular-cli体系结构进行应用程序的初始设置。angular-cli:在src目录中导入node_modules文件

我想将一些全局css文件导入到我的index.html文件中。但作为node_modules目录是在我的src目录之外,我没有得到准确的路径,因此css没有应用。

我用了以下寡情路径,

无我有../也试过,但它也不能正常工作。

for ex。

<link href="node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/> 

& &

<link href="../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/> 

但这两种方式都不能正常工作。

我在做什么错?

这里是应用程序结构。

enter image description here

我使用的角度2.2.1

以下是错误我得到

enter image description here

在此先感谢

+0

你有没有[检查你的控制台吗?](http://stackoverflow.com/documentation/javascript/185/getting-started-with-javascript/714/using-console-log)你是否收到404错误?你是否在服务器上提供'node_modules'? –

+0

是的。我已经更新了屏幕的问题 –

+0

也许[这个答案](http://stackoverflow.com/questions/37844334/add-the-css-from-the-node-modules-folder-using-angular-cli)将帮助你 – Shaho

回答

4

检查的角度的documentation关于如何安装全球图书馆的CLI,

您必须修改您的angular-cli.json文件以将CSS文件包含在捆绑式样式文件中,而不是直接在HTML中使用。

"styles": [ 
    "../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" 
] 

希望这有助于!

+0

感谢Madhu 在angular-cli.json中添加了路径,但是我应该在index.html中编写什么? –

+0

@PinankLakhani没事。 – Chrillewoodz

+0

当你将它添加到styles文件夹时,CLI将文件捆绑到'styles.bundle'中,这样你就不必在HTML中添加任何东西,干杯! –