Getting MathJax to update after changes to AngularJS model

后端 未结 10 619
甜味超标
甜味超标 2020-11-30 02:02

I am trying to use AngularJS two-way binding text which includes Latex style equations. I would like to call MathJax to format the equations, but I\'m not sure of the best

10条回答
  •  失恋的感觉
    2020-11-30 02:40

    I Build a directive for this....

    FIDDLE: http://jsfiddle.net/8YkUS/1/

    HTML

    p data-math-exp data-value="math">

    JAVASCRIPT

     appFlipped.directive("mathExp", function () {
        return {
            scope: {
                value: "="
            },
            link: function (scope, el) {
    
                var domEl = el[0];
                scope.$watch("value", function (newValue) {
    
                    //nothing to do here
                    if (newValue == null || window.MathJax == null)return;
    
                    //update the dom with the new value and pass the hub for styling the equation
                    domEl.innerHTML = '`' + newValue + '`';
                    MathJax.Hub.Queue(["Typeset", MathJax.Hub, domEl]);
                });
            }
        }
    });
    

提交回复
热议问题