出于明显的原因(防止攻击),我使用以下两个过滤器的组合首先从用户输入中删除所有HTML,然后替换标记中的所有\n。filters.filter('newlines',function(){returnfunction(text){console.log(text)returntext.replace(/\n/g,'');}})filters.filter('noHTML',function(){returnfunction(text){returnBoolean(text)?text.replace(/&/g,'&').replace(/>/g,'>').replace(
我正在使用Angularjs开发一个应用程序,并在我的页面中使用$sce.trustAsHtml()添加HTML。我想在上面动态添加的内容中调用一个函数。我的html和脚本如下。HTMLJavascriptangular.module('ngBindHtmlExample',['ngSanitize']).controller('ngBindHtmlCtrl',['$scope','$sce',functionngBindHtmlCtrl($scope,$sce){$scope.myHTML=$sce.trustAsHtml('IamanHTMLstringwithlinks!ando
我正在尝试将$sce.trustAsHtml()与ng-repeat中的对象属性一起使用。结果是HTML完全空白。尽管HTML使用ngSanitize正确输出。顺便说一下,我在使用AngularJSv1.3.0-beta.3。不确定是否存在错误或我做错了什么。 最佳答案 您不能在表达式中使用$sce.trustAsHtml(除非$sce是$scope的属性)因为表达式在$scope的上下文中进行评估。最干净的方法是使用ngSanitize。第二个最干净的方法是将$sce.trustAsHtml作为$scope中的函数公开:$scop