【发布时间】:2013-12-15 14:28:49
【问题描述】:
我想在 angularjs 1.2 中使用 unsafe-html。没有 html 的过滤器确实可以工作,而 html 则不能。我的工作:
我在我的 html 头中添加了 angular-sanitize:
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-sanitize.js"></script>
我的角度模块:
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
【问题讨论】:
标签: javascript html angularjs