简体   繁体   English

在ngFor Angular(2/4/5)中使用MathJax

[英]Use MathJax in ngFor Angular (2/4/5)

So, I've been trying to render mathematical equations on Angular 4 application using MathJax. 因此,我一直在尝试使用MathJax在Angular 4应用程序上渲染数学方程。 Everything is working fine till I had to render single equation. 一切工作正常,直到我不得不渲染单个方程式为止。 But now I need to render the around 4 equations which is coming from an API. 但是现在我需要渲染大约4个来自API的方程式。

Now, using the MathJax inside ngFor works only for the first object in the array but not after that. 现在,在ngFor中使用MathJax仅适用于数组中的第一个对象,但不适用于此对象。 See screenshot below: 请参见下面的屏幕截图:

在此处输入图片说明

My HTML looks like this: 我的HTML看起来像这样:

<div class="card">
    <div class="card-header">
        //question HTML
    </div>
    <div *ngFor="let answer of model.question?.options">
        <span class="answers" #answers>{{answer?.text}}</span>
    </div>
</div>

And, the component looks like this: 并且,该组件如下所示:

@ViewChild('equation') equation: ElementRef;

MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.equation.nativeElement]);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.answers.nativeElement]);

Try: 尝试:

<div class="card">
    <div class="card-header">
        //question HTML
    </div>
    <div *ngFor="let answer of model.question?.options">
        <span class="answers">{{answer?.text}}</span>
    </div>
</div>

@ViewChild('equation') equation: ElementRef;

MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.equation.nativeElement]);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, document.getElementsByClassName("answers")]);

'# sintaxis is unique. '#sintaxis是唯一的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM