我通过运行以下命令在角6.我已经安装了Mathjax项目
npm install mathjax
和npm 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';