角度过滤器返回 html [英] Angular filter return html

查看:30
本文介绍了角度过滤器返回 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 angularjs 1.2 中使用 unsafe-html.而没有 html 的过滤器可以工作,而带有 html 的过滤器则不行.我做什么:

I want to use unsafe-html in angularjs 1.2. Whereas the filter without html does work, with html it does not. What I do:

我在我的 html 头中添加了 angular-sanitize:

I added angular-sanitize to my html head:

<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

推荐答案

ng-bind-html-unsafe 已在 Angular 1.2 中删除.由于您正确地清理了您的输入,您应该只使用 ng-bind-html.

ng-bind-html-unsafe has been removed in Angular 1.2. Since you are correctly sanitizing your input, you should just use ng-bind-html.

示例:http://plnkr.co/edit/0bHeXrarRP7IAciqAYgM?p=preview

这篇关于角度过滤器返回 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆