I have run command npm install mathjax and npm install --save @types/mathjax
and added reference of mathjax.js in angular-cli.json
"../node_modules/mathjax/mathjax.js?config=TeX-AMS-MML_HTMLorMML"
. I have created directive
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]);
}
}
this showing error Mathjax ReferenceError: MathJax is not defined
I have added mathjax in types of tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": [
"mathjax"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}