Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在angularjs中使用ng bind html解析自定义html元素_Angularjs_Ng Bind Html - Fatal编程技术网

如何在angularjs中使用ng bind html解析自定义html元素

如何在angularjs中使用ng bind html解析自定义html元素,angularjs,ng-bind-html,Angularjs,Ng Bind Html,我需要使用ng bind html解析字符串。此字符串中包含一些自定义html标记。在使用ng bind html进行解析时,它为$sanitize:badparse提供了一个错误 请查看小提琴的错误: 在阅读stackoverflow和google中的问题时,我发现如果我使用$sce.trustAsHtml(),可能会有一个解决方案 这解决了我的错误问题,但无法解析我的自定义html元素。 您可以在此处看到此更新的小提琴: 我绞尽脑汁想找到解决办法 编辑: 只是为了添加更多信息,我从rss源中

我需要使用ng bind html解析字符串。此字符串中包含一些自定义html标记。在使用ng bind html进行解析时,它为$sanitize:badparse提供了一个错误

请查看小提琴的错误:

在阅读stackoverflow和google中的问题时,我发现如果我使用
$sce.trustAsHtml()
,可能会有一个解决方案

这解决了我的错误问题,但无法解析我的自定义html元素。 您可以在此处看到此更新的小提琴:

我绞尽脑汁想找到解决办法

编辑:
只是为了添加更多信息,我从rss源中获取了这个字符串,因此有时它可能有
”嗯,我成功地获得了锚定、下划线和粗体等工作标记,没有问题,看:

angular.module('ngBindHtmlExample',['ngSanitize']))
.controller('ngBindHtmlCtrl',['$scope',函数ngBindHtmlCtrl($scope){
$scope.myHTML=
“OMB通告A-76的竞赛”;
}])
.filter('to_trusted',['$sce',function($sce){
返回函数(文本){
返回$sce.trustAsHtml(文本);
}; 
}]);

似乎它被正确解析了

这很好,但是如果我有像“”或“it”这样的标记,该怎么办呢?它工作正常,您只需要使用正确的语法。很好,但是这个“”和结束元素这是个问题,我们从rss提要获取这个字符串,在将它插入数据库之前,我们将用前50个字符截断该字符串。现在它可以有一个结束'
angular.module('ngBindHtmlExample', ['ngSanitize'])
  .controller('ngBindHtmlCtrl', ['$scope', function ngBindHtmlCtrl($scope) {
    $scope.myHTML =
        '<a href=\"http://google.com\">link</a> contests <u>of OMB</u> <b>Circular</b> A-76';
  }])
    .filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);
        }; 
}]);