dan*_*iel 16 html javascript angularjs
我想在angularjs 1.2中使用unsafe-html .没有html的过滤器确实有效,而html没有.我所做的:
我在我的html头部添加了angular-sanitize:
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-sanitize.js"></script>
Run Code Online (Sandbox Code Playgroud)
我的角度模块:
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");
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的Html:
<td><span ng-bind-html="f.state | convertstate"></span></td>
Run Code Online (Sandbox Code Playgroud)
编辑:更新ng-bind-html-unsafe到ng-bind-html
mus*_*_ut 22
ng-bind-html-unsafe已在Angular 1.2中删除.由于您正确地清理了输入,因此您应该使用ng-bind-html.
示例:http://plnkr.co/edit/0bHeXrarRP7IAciqAYgM?p = preview
| 归档时间: |
|
| 查看次数: |
21111 次 |
| 最近记录: |