angular 2 - adding 3rd party libs

后端 未结 8 1852
盖世英雄少女心
盖世英雄少女心 2020-11-28 09:22

I am trying to start using angular 2 cli.
I want to use momentjs in my project so here is what I have done:
1. created project using angular cli.
2. run np

8条回答
  •  無奈伤痛
    2020-11-28 09:49

    If library you want to include is not in typings you have two ways to include it in an angular 2 application:

    1. using npm: step a. install library using package manager

      step b. add path of the library to the map object in systemjs.config.js file.

    example:

    'jquery' : 'npm:jquery/dist/jquery.js', 'd3' : 'npm:d3/build/d3.js'

    step c. import it in app.module.ts example:

    import 'jquery'; import 'd3';

    step d. declare it

    example: declare var $: any;

    declare var d3: any;

    1. simply you can include that in script tag in index.html and declare it.

提交回复
热议问题