【问题标题】:How to add a NPM package correctly in the plunker?如何在 plunker 中正确添加 NPM 包?
【发布时间】:2016-06-16 21:55:50
【问题描述】:

我在使用 angular2-infinite-scroll 时收到了 error。我想在 plunkr 中重现它。

我尝试使用npmcdn,所以我在index.html文件中添加了这一行:

<script src="https://npmcdn.com/angular2-infinite-scroll@0.1.2"></script>

但我得到了错误:

Uncaught ReferenceError: require is not defined

这是我的plunker

如何在 plunker 中正确添加 NPM 包?

【问题讨论】:

  • 将其添加到您的config.js 文件中的map 对象中,如果包没有index.js,也可能添加到packages 对象中。

标签: angular npm plunker


【解决方案1】:

将其添加到您的config.js 文件中的map 对象中,如果包没有index.js,也可能添加到packages 对象中。

map: {
    [...],
    'angular2-infinite-scroll': 'https://npmcdn.com/angular2-infinite-scroll@0.1.2'
},
packages: {
    [...],
    'angular2-infinite-scroll': {
        main: 'angular2-infinite-scroll.js',
        defaultExtension: 'js'
    }
},

工作Plunker

【讨论】:

  • 谢谢!但我认为你给我的 Plunker 链接是错误的.. 或者你没有保存
  • 呃,忘记保存了:)
  • 嗯,angular2-infinite-scroll 0.1.2 应该可以正常工作。因为我遇到的错误只在 0.1.3 中。也许在 plunker 中还有什么问题?
  • 哦,我在你的插件中发现了错误。在 app.ts 中删除重复的directives: [] 后,错误消失了!
  • 我将带有onScroll 功能的工作版本留在这里:plnkr.co/edit/uof65imnVnMooMlBksoe?p=preview
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-15
  • 2012-10-06
  • 2016-09-07
相关资源
最近更新 更多