我想在 angularjs 1.2 中使用 unsafe-html。没有 html 的过滤器可以工作,而有 html 则不行。我的工作:
我在我的 html 头部添加了 angular-sanitize:
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-sanitize.js"></script>
我的 Angular 模块:
var myApp = angular.module('myApp', ['ngSanitize'])
.filter('convertState', function ($sce) {
return function (state) {
if (state == 1) {
return $sce.trustAsHtml("<strong>" + state + "</strong> special state");
}
else {
return $sce.trustAsHtml("<strong>"+state + "</strong> normal state");
}
}
});
我的 HTML:
<td><span ng-bind-html="f.state | convertstate"></span></td>
编辑:将 ng-bind-html-unsafe
更新为 ng-bind-html
最佳答案
ng-bind-html-unsafe
已在 Angular 1.2 中删除。由于您正确地清理了输入,因此您应该只使用 ng-bind-html
。
关于javascript - Angular 过滤器返回 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284965/