# 如何在 angular 中使用 mathquill

# angular8 使用 ngx-mathquill

# 引入 Jquery ,并需要全局配置

mathquill 基于 Jquery 实现,所以需要引入 Jquery

  1. 安装 npm 包
npm install jquery --save
npm install @types/jquery
1
2
  1. tsconfig.json
{
  "types": ["jquery"]
}
// types用于指定需要包含的模块,只有在这里列出的模块的声明文件才会被加载
1
2
3
4
  1. angular.json
{
  "scripts": ["node_modules/jquery/dist/jquery.slim.min.js"]
}
// jquery.slim.min.js是移除了ajax和特效的版本
1
2
3
4

之后 在项目中 可以全局使用 Jquery $;

# 引入 ngx-mathquill

  1. 安装 npm 包
npm install ngx-mathquill
1
  1. 引入 mathquill 样式文件

angular.json

{
  ...
  "options": {
    "assets": [
      "src/favicon.ico", "src/assets",
      { "glob": "**/*", "input": "./node_modules/ngx-mathquill/mathquill/", "output": "./mathquill/" }
    ],
  }
}
1
2
3
4
5
6
7
8
9
  1. 页面中使用

component.ts

import { MathQuillLoader } from 'ngx-mathquill'
MathQuillLoader.loadMathQuill(mathquill => {
  // do what you want here
  // for example:
  // console.log(mathquill.getInterface(2));
  const MQ = mathquill.getInterface(2);
  const box = document.getElementById('box');
  MQ.StaticMath(box);;
})
1
2
3
4
5
6
7
8
9
上次更新: 2022-11-29 16:59:20(UTC +8)