繁体   English   中英

Angular 6 Mathjax不起作用

[英]Angular 6 mathjax not working

我在angular 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字符串,而不是制作数学方程式

您需要在指令中导入MathJax。

import * as Mathjax from 'mathjax';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM