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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 ;) )
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.