Getting MathJax to update after changes to AngularJS model

后端 未结 10 642
甜味超标
甜味超标 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:25

    A simple solution is to use $timeout to put MathJax.Hub.Queue(["Typeset", MathJax.Hub]) in the browser event queue (see Run a directive after the DOM has finished rendering).

    Something like this:

                var app = angular.module('myApp', []);
                app.controller('myController', function ($scope, $timeout) {
                    controller = this;
    
                    $scope.Update = function () {
                        $scope.value = " \\( \\frac{5}{4} \\div \\frac{1}{6} \\)";
                        $timeout(controller.updateMathJax, 0);
                    }
    
                    this.updateMathJax = function () {
                        MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
                    }
                });
    

提交回复
热议问题