You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular集成TinyMCE 6外部MathType插件加载失败求助

Angular + TinyMCE 集成 MathType 插件解决方案

错误原因

你配置的插件路径node_modules/@wiris/mathtype-tinymce6/plugin.min.js无法在Angular运行时访问——Angular构建打包后不会保留node_modules的直接访问路径,导致插件加载失败。

解决步骤

1. 确认依赖安装

确保已正确安装MathType插件包:

npm install @wiris/mathtype-tinymce6 --save

2. 配置Angular静态资源复制

修改angular.json,将插件文件复制到项目assets目录,确保构建后可正常访问:

"assets": [
  "src/favicon.ico",
  "src/assets",
  {
    "glob": "plugin.min.js",
    "input": "./node_modules/@wiris/mathtype-tinymce6/",
    "output": "./assets/mathtype/"
  }
]

3. 修正TinyMCE配置

调整组件中的tinymceConfig,修正插件路径并移除冗余配置:

export class PageComponent {
  tinymceConfig = {};
  constructor(private request: RequestService) {
    this.tinymceConfig = {
      external_plugins: {
        'tiny_mce_wiris': 'assets/mathtype/plugin.min.js',
      },
      toolbar: 'tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry',
      draggable_modal: true,
      extended_valid_elements: '*[.*]',
      plugins: 'lists link image table code help wordcount', // 外部插件无需加入plugins数组
      language: 'ru',
    };
  }

  async testEvent() {
    await this.request.postRequest(`${environment.apiUrl}/api/auth/account/islogging`, []);
  }
}

4. 补充公式渲染依赖(可选但建议)

MathType需要MathJax渲染公式,在index.html中添加MathJax脚本:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML"></script>
<script>
  MathJax.Hub.Config({
    showMathMenu: false,
    tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }
  });
</script>

完成以上步骤后,重启Angular项目,MathType插件即可正常加载使用。

内容的提问来源于stack exchange,提问作者Бекзат Сайлаубаев

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 21:57:32