1

Can someone please help me how to use mathjs in ionic 2? I just don't get it imported to use, really don't know what to do.

In ionic 1 it was easy to load the library and use it, but not so in ionic 2.

Thanks!

bastifix
  • 443
  • 1
  • 6
  • 18

1 Answers1

6

try this

npm install mathjs --save
npm install @types/mathjs --save-dev

in Component:

import * as math from 'mathjs'; // don't named as Math, this will conflict with Math in JS

in some method:

let rs = math.eval('cos(45 deg)');

or you could using CDN:

add this line into index.html

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

in Component:

// other import ....;
declare const math: any;

in some method:

let rs = math.eval('cos(45 deg)');
Tiep Phan
  • 12,386
  • 3
  • 38
  • 41