2

在 AngularJS 分页中,我使用 KaTeX JavaScript 库来计算数学方程。

问题:当我要转到下一页时,库不工作。请帮助我理解,我做错了什么?这是我的 app.js 和 index.html 代码。这是我的 app.js。

var app = angular.module('app', ['ngRoute', 'bw.paging', 'paging', 
'katex']);  
app.controller('homeCtrl', ['$scope', '$http', function($scope, $http)
{  
$scope.yo= {  
    'opted' : '',  
}  
$scope.var = 7;  
$scope.equations = [{'name' : 'Integration', 'notation' : '\\(k_{n+1} 
= n^2 + k_n^2 - k_{n-1}\\)'},  
                    {'name' : 'Summation', 'notation' : 
'90${}^\\circ$'},  
                    {'name' : 'Union', 'notation' : '\\(ax^2 + bx + c 
= 0\\)'},  
                    {'name' : 'integration', 'notation' : 
'$f(x)=a_0+\\int^{\\infty }_{n=1}{(a_n{\\mathrm{cos} \\frac{n\\pi x}
{L}\ }+b_n{\\mathrm{sin} \\frac{n\\pi x}{L}\\ })}$'},  

];  
  $scope.submitTest = function(questions){  
        var marks =0;  
        for(var i =0;i < questions.length; i++){  
            console.log(questions[i].opted);  
            console.log('hi');  
            if(questions[i].correct_options == questions[i].opted)
                marks = marks +1;  
        }  
        console.log(marks);  
    };  


$scope.currentPage = 0;  
$scope.pageSize = 1;  
$scope.data = [];  
$scope.q = '';  


$scope.numberOfPages=function(){  
    return Math.ceil($scope.equations.length/$scope.pageSize);                  
}  


}]);  

//We already have a limitTo filter built-in to angular,  
//let's make a startFrom filter  
app.filter('startFrom', function() {  
    return function(input, start) {  
        start = +start; //parse to int  
        return input.slice(start);  
    }  
  });  

this is my index.html  
 <div ng-repeat="item in equations | filter:q | 
  startFrom:currentPage*pageSize | limitTo:pageSize">  
      <katex auto-render ng-bind="item.notation"></katex>  
    </div>  
    <button ng-disabled="currentPage == 0" ng-
 click="currentPage=currentPage-1">  
        Previous
    </button>  
    {{currentPage+1}}/{{numberOfPages()}}  
    <button ng-disabled="currentPage >= equations.length/pageSize - 1" 
 ng-click="currentPage=currentPage+1">  
        Next
    </button>  
4

2 回答 2

1

为了在不刷新页面的情况下动态呈现数学方程,我使用了 MathJax 的主处理队列。使用 MathJax.Hub.Queue() 将回调推送到此队列。

app.directive('mathjax',function(){
return {
    restrict: 'EA',
    link: function($scope, attrs) {
        $scope.$watch(attrs.ngModel, function () {
            MathJax.Hub.Queue(['Typeset',MathJax.Hub]);
        });
     }
   };
});
于 2017-10-12T16:33:14.787 回答
0

这里的问题是文档对象没有重新渲染。你可以试试这个自动渲染。 https://github.com/Khan/KaTeX/tree/master/contrib/auto-render

否则,请尝试使用 katax 和 angularJS 的示例摘录。 http://lucasbardella.com/blog/2014/11/katex-angularjs

于 2017-10-10T17:32:06.520 回答