我想尝试使用 angular-cli ( https://github.com/angular/angular-cli ) 创建一个 Angular 2 应用程序,然后将 ng2-material ( https://github.com/justindujardin/ng2-material ) 用于 UI 组件。但我只是不明白我必须如何/在何处包含 ng2-material 库才能使用它。
我用 ng new myproject
创建了一个项目,然后用 ng serve
启动了服务器并打开了运行正常的网页。下一步,我使用 npm install ng2-material --save
安装了 ng2-material。然后我将 MATERIAL_PROVIDERS
添加到 angular 的 Bootstrap 中,如此处所示 https://github.com/AngularShowcase/angular2-seed-ng2-material/blob/master/app/bootstrap.ts .
这会导致 Web 浏览器中出现错误消息 GET http://localhost:4200/ng2-material/all 404 (Not Found)
,我只是不知道如何摆脱它。
angular-cli 似乎正在做一些事情来创建一个 dist
文件夹,其中 index.html 中使用的一些节点模块最终位于其中,但我看不到在哪里或这是如何配置的。
最佳答案
[EDIT 29/09/2016] 现在 angular-cli 使用的是 webpack iso system.js,这个答案不再有意义了。检查页面 ' 3d party lib installation ' 和 ' global lib installation ' 在 angular-cli wiki 上。
[EDIT 10/05/2016] 现在在 angular cli wiki 上对此进行了详细描述。 .
这对我有用:
在 ember-cli-build.js 中,您将依赖项添加到 vendorNpmFiles,例如
module.exports = function (defaults) {
var app = new Angular2App(defaults, {
vendorNpmFiles: [
'a2-in-memory-web-api/web-api.js'
]
});
return app.toTree();
}
(其中 a2-in-memory-web-api/web-api.js 是我的 node_modules 文件夹中的一个文件)
在 index.html 中添加以下行:
<script src="vendor/a2-in-memory-web-api/web-api.js"></script>
最后你重启了你的服务器。
还没有用 Angular Material 测试它,但你明白了。
关于angular - 使用angular-cli时如何添加第三方库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35690663/