角6 mathjax不工作

问题描述 投票:1回答:1

我通过运行以下命令在角6.我已经安装了Mathjax项目

npm install mathjaxnpm install --save @types/mathjax

我创建指令

    import { Directive, Input, OnChanges, ElementRef, OnInit } from '@angular/core';

    @Directive({
      selector: '[Mathjax]'
    })
    export class MathjaxDirective implements OnChanges {

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

      constructor(private element: ElementRef) {
      }


      ngOnInit() {
        this.update();
      }

      ngOnChanges() {
        this.update();

      }

      update() {

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

      }

    }

我使用这个指令

<span [Mathjax]="mathjaxTest"></span>

它的显示没有错误在控制台,它不工作。它打印mathjax字符串,而不是做数学方程。

angular mathjax
1个回答
0
投票

您需要导入MathJax在你的指令。

import * as Mathjax from 'mathjax';
© www.soinside.com 2019 - 2024. All rights reserved.