离子2中的MathJS

bas*_*fix 1 mathjs ionic2

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

在ionic 1中,加载和使用库很容易,但在ionic 2中则不是。

谢谢!

Tie*_*han 5

尝试这个

npm install mathjs --save
npm install @types/mathjs --save-dev
Run Code Online (Sandbox Code Playgroud)

在组件中:

import * as math from 'mathjs'; // don't named as Math, this will conflict with Math in JS
Run Code Online (Sandbox Code Playgroud)

用某种方法:

let rs = math.eval('cos(45 deg)');
Run Code Online (Sandbox Code Playgroud)

或者您可以使用CDN:

将此行添加到 index.html

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.1/math.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

在组件中:

// other import ....;
declare const math: any;
Run Code Online (Sandbox Code Playgroud)

用某种方法:

let rs = math.eval('cos(45 deg)');
Run Code Online (Sandbox Code Playgroud)