Théophile
Théophile

Reputation: 1031

how do I import a library in Ionic 1?

I'm learning Ionic to build an app that requires some linear algebra. It seems that I have to somehow import mathjs into my project.

So far, I've done this in my project's folder:

npm install mathjs --save

But now what? Where do I actually import it? I've tried writing

import math from 'math'

in app.js, inside angular.module() { ... }. When I do this, I get:

SyntaxError: import declarations may only appear at top level of a module

I've also tried adding

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

in index.html, but that doesn't work either. I've spent all afternoon trying to find documentation or examples, but to no avail. What am I missing?

Upvotes: 2

Views: 845

Answers (1)

Fetrarij
Fetrarij

Reputation: 7326

For ionic v1, You just need to include the mathjs library in index.html page, and mathjs exposes the global math object , so you don't need to inject anything, you can call it whenever you want in your app.

if you use bower, just install the lib by,

bower install mathjs --save

then

<script src="path/to/bower_components/mathjs/dist/math.min.js" type="text/javascript"></script>

or you can use a cdn

add this in index.html

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.1/math.min.js"></script>

Upvotes: 1

Related Questions