1

有人可以帮我如何在 ionic 2 中使用 mathjs 吗?我只是不把它导入使用,真的不知道该怎么办。

在 ionic 1 中,很容易加载库并使用它,但在 ionic 2 中并非如此。

谢谢!

4

1 回答 1

6

试试这个

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

在组件中:

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

以某种方式:

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

或者您可以使用 CDN:

将此行添加到index.html

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

在组件中:

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

以某种方式:

let rs = math.eval('cos(45 deg)');
于 2017-02-11T07:00:51.390 回答