Я выполнил команду npm install mathjax и npm install --save @ types / mathjax
и добавил ссылку на mathjax.js в angular-cli.json
"../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 не определен
Я добавил mathjax в типах tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": [
"mathjax"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}