angular - 使用angular-cli时如何添加第三方库?

标签 angular angular-material angular-cli

我想尝试使用 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/

相关文章:

Angular:在子路由上设置特定的路由链接处于事件状态

angular - 选择路由器链接时,所有设备的侧边导航都将关闭

Angular Material 2 Reactive Forms -- mat-error with *ngIf 在验证 minLength、电子邮件和所需的验证工作时未显示

用 Material 编写的 Angular Testing 模板驱动形式

angular - ES6 : Property 'selected' does not exist on type 'Object'

angular - 使用具有多路径代理匹配的 angular-cli

javascript - 构建 Angular 项目后图像未显示

javascript - Angular 5 TypeScript——包括 ES2015 代码

angular - 有谁知道如何在 component.ts 文件中使用 titlecase 而不是在 html 文件中?

javascript - Angular - Mat Paginator : Multiple Tables in a component