How to import a npm package in an angular2 component?

流过昼夜 提交于 2019-12-05 01:59:49

I have some comments here:

  • You should configure SystemJS this way for your module:

    System.config({
      map:{'arpad':'node_modules/arpad/index.js'}
      packages: {        
        app: {
          format: 'register',
          defaultExtension: 'js'
        }
      }
    });
    
  • You don't need to import your index.js file (see System.import('node_modules/arpad/index.js');) before importing your application (importing the app/main module).

  • You need to import your elo object this way:

    import * as Elo from 'arpad';
    
  • Then you should be able to use your module this way:

    constructor() {
      this.elo = new Elo();
      this.score = this.elo.expectedScore(200, 1000);
    }
    

Here is a plunkr describing this: https://plnkr.co/edit/K6bx97igIHpcPZqjQkkb?p=preview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!