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

问题描述

我想在使用不安全的-HTML angularjs 1.2 。而无需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:

我添加角的sanitize到我的HTML头:

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-结合HTML的不安全 NG-绑定-HTML

推荐答案

NG-结合HTML的不安全已经在1.2角去除。既然你正确消毒你的投入,你应该只使用 NG-绑定-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.

例如:<一href=\"http://plnkr.co/edit/0bHeXrarRP7IAciqAYgM?p=$p$pview\">http://plnkr.co/edit/0bHeXrarRP7IAciqAYgM?p=$p$pview

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

08-31 06:16