angular 2 - adding 3rd party libs

后端 未结 8 1810
盖世英雄少女心
盖世英雄少女心 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 10:01

    I’m not currently using moment.js myself right now. So I’m not sure, but it seems to me that you are trying to use moment.js as a typescript module and maybe it is not a typescript module. I suggest another approach. Do not use moment.js as module to import but use a d.ts file instead. To accomplish this I’m use tsd: Open a cmd:

    • npm install tsd -g
    • Global install of tsd

    • cd [your project dir]
    • Change to your project root

    • tsd init
    • Among another things, Creates a tsd.json file to keep track of your installed d.ts files

    • tsd install moment -save

    After this I did get code completion in typescript after: moment.

    Did not test further...

    I'm now using typings, instead of tds, as manager for TypeScript definitions. Tds is now deprecated.

    You probably can install moment.d.ts like this: typings install moment --ambient --save

    0 讨论(0)
  • 2020-11-28 10:05

    The answer can be found in the following link: https://github.com/angular/angular-cli/issues/274#issuecomment-192490084

    0 讨论(0)
提交回复
热议问题