How to get Mathjax working with Angular2?

前端 未结 4 869
春和景丽
春和景丽 2020-12-16 03:34

Has anyone gotten Mathjax working with Angular2 ?

Plunkr example created :- http://plnkr.co/edit/FLduwmtHfkCN5XPfzMsA?p=preview

From some Angular1 example

4条回答
  •  难免孤独
    2020-12-16 04:22

    I would implement this way with an input to get the specified expression:

    import {Directive, ElementRef, Input} from 'angular2/core';
    @Directive({
        selector: '[MathJax]'
    })
    export class MathJaxDirective {
        @Input(' MathJax')
        texExpression:string;
    
        constructor(private el: ElementRef) {
        }
    
        ngOnChanges() {
           this.el.nativeElement.innerHTML = this.texExpression;
           MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.el.nativeElement]);
        }
    }
    

    And use this way:

    
    
    

    See this plunkr: http://plnkr.co/edit/qBRAIxR27zK3bpo6QipY?p=preview.

提交回复
热议问题