Javascript 如何在Angularjs中将文本绑定为DOM对象

Javascript 如何在Angularjs中将文本绑定为DOM对象,javascript,angularjs,dom,Javascript,Angularjs,Dom,我想用Angularjs动态显示MathMLDOM对象 这是我写的: var mathML = angular.module('mathML', ['ngSanitize']); mathML.controller('mathMLCtrl', ['$scope', function ($scope) { $scope.result = function(){ return "<math xmlns='http://www.w3.org/1998/Math/MathML'>

我想用
Angularjs
动态显示
MathML
DOM对象

这是我写的:

var mathML = angular.module('mathML', ['ngSanitize']);

mathML.controller('mathMLCtrl', ['$scope', function ($scope) {
  $scope.result = function(){
    return "<math xmlns='http://www.w3.org/1998/Math/MathML'><msup><msqrt><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></msqrt><mn>27</mn></msup></math>";
    //return "<p>p tag</p>";
  };
}]);
var mathML=angular.module('mathML',['ngSanitize']);
控制器('mathMLCtrl',['$scope',函数($scope){
$scope.result=函数(){
返回“a+b27”;
//返回“p标签”

”; }; }]);
使用
ngbindhtml
,我可以将文本作为html文本插入,但是
MathML
的XML没有正确插入。(将删除所有标记。)

似乎有必要将
MathML
文本作为DOM对象插入。但我不知道怎么做


如何使用
Angularjs
显示
MathML

ng bind html通过删除未列为“安全”的标记来清理输出。数学标记未列在允许的标记下。如果您相信这个html永远不会有漏洞,那么您将希望使用$sce服务将代码标记为可信。看看这个答案:

另一种选择是将此文本保存为部分文本,保存在它自己的单独文件中。然后在html中,使用ng include将部分加载到dom中