【发布时间】:2018-11-10 01:07:06
【问题描述】:
我已经运行命令 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 is not defined
我在 tsconfig.app.json 类型中添加了 mathjax
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": [
"mathjax"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
【问题讨论】: