在Typescript中导入一个简单的Javascript文件

时间:2016-06-08 09:29:51

标签: javascript typescript ionic2

我正在使用离子2 beta,我尝试制作一个简单的学习计算器。我想使用math.js库(http://mathjs.org),但我不知道如何导入此文件以在我的打字稿代码中使用它。

例如:

export class HomePage
{
    constructor() {}

    calculate()
    {
        // Here I want to use math.js
    }
}

我尝试了以下内容:

export class HomePage
{
    var m = require('path/to/math.js');

    constructor() {}

    calculate()
    {
        m.math.parse(expression); // assuming expression is defined
    }
}

但我收到错误undefined is not an object (evaluating 'm.math.parse')

1 个答案:

答案 0 :(得分:0)

您可以在index.html内添加脚本

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