簡體   English   中英

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

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

因此,我一直在嘗試使用MathJax在Angular 4應用程序上渲染數學方程。 一切工作正常,直到我不得不渲染單個方程式為止。 但是現在我需要渲染大約4個來自API的方程式。

現在,在ngFor中使用MathJax僅適用於數組中的第一個對象,但不適用於此對象。 請參見下面的屏幕截圖:

在此處輸入圖片說明

我的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>

並且,該組件如下所示:

@ViewChild('equation') equation: ElementRef;

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

嘗試:

<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是唯一的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM