2

I'm trying to use this external javascript library CamanJS with my Ionic2 (typescript project)

I've found several articles like this and this, however all of them assumes the library that is going to use is in typings

But CamanJS is not yet in the typings and there is a open ticket for it

my question is, is there a way to add an external js library (which is not yet added to typings) to an ionic2 (typescript) project?

vitr
  • 6,766
  • 8
  • 30
  • 50
sameera207
  • 16,547
  • 19
  • 87
  • 152

1 Answers1

1

Let me describe this process in a common case:

  1. To include a JavaScript library in your TypeScript application you must first include it in your HTML file as a script tag.

    <script src="js/your_external_library.js"></script>

  2. To use the library you must add the following to one of your ts files:

    declare var libraryVar: any;

  3. Replace libraryVar with a variable, function, or class within your JavaScript library.

At this point it is ready for use.

  1. After these steps you can use your external library with API which it provides. For example:

    this.libraryVar = new libraryVar(parameters);

  2. Call tsc and .ts file compiled into .js with properly syntax and with your external library.

Community
  • 1
  • 1
Alex Filatov
  • 2,232
  • 3
  • 32
  • 39
  • hey @alex , thanks for and answer and sorry for the delay on replying, I'll try this over this weekend and see how it goes. (Of course will accept if works ;) ) – sameera207 Jul 29 '16 at 11:28
  • Thanks for the answer. I was able to get it working with the help of you and sebaferreras. My new question with some more details is [here](http://stackoverflow.com/questions/39061305/using-a-normal-js-librarary-with-ionic2-typescript/39061346#39061346) – sameera207 Aug 21 '16 at 08:07