MathJax未定义角度4

时间:2018-05-31 05:24:34

标签: angular mathjax

我已经运行命令npm install mathjax和npm install --save @ types / mathjax

并在angular-cli.json

中添加了mathjax.js的引用
"../node_modules/mathjax/mathjax.js?config=TeX-AMS-MML_HTMLorMML"

。我已经创建了指令

import { Directive, Input, OnChanges, ElementRef } from '@angular/core';
    declare var MathJax: any;

    @Directive({
    selector: '[MathJax]'
    })
    export class MathJaxDirective implements OnChanges {

        @Input('MathJax') private value: string;

        constructor(private element: ElementRef) {

    }

    ngOnChanges() {

        // console.log('- onChange -');
        // console.log(this.value);

        this.element.nativeElement.innerHTML = this.value;
        MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.element.nativeElement]);
        }

    }

显示错误Mathjax ReferenceError:MathJax未定义

我在tsconfig.app.json的类型中添加了 mathjax

        {
      "extends": "../tsconfig.json",
      "compilerOptions": {
        "outDir": "../out-tsc/app",
        "baseUrl": "./",
        "module": "es2015",
        "types": [
          "mathjax"
        ]
      },
      "exclude": [
        "test.ts",
        "**/*.spec.ts"
      ]
    }       

1 个答案:

答案 0 :(得分:0)

您正在获取MathJax'undefined',因为它未加载到您的浏览器中。 要么添加

$meter = Installations::find()->where(['meter_msn'=>$msn])->one();

或替换

 <script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>

declare var MathJax: any;

将“mathjax”添加到src / tsconfig.app.json中的types数组中。