-->

角消毒/ NG绑定,HTML不工作?(Angular sanitize / ng-bind-html

2019-07-19 08:39发布

我有一个中继器设置,并能得到,只要有内它没有HTML数据显示。

我已经包括angular-sanitize.js和使用都试过ng-bind-html

但没有什么是跨度内显示,仅在ng-bind-html属性。 所以它看起来像sanitize方法是行不通的,

我读这需要添加到应用程序的依赖关系,但我不知道在哪里这样做。

我刚刚被通过对角部位的啧啧工作,所以只需要在一分钟建立一个非常基本的控制器。

Answer 1:

  1. 您需要包括角sanitize.js http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js

  2. “ngSanitize”添加到你模块依赖

    VAR对myApp = angular.module( '对myApp',[ 'ngSanitize']);

  3. 不要使用{{}}中的属性

    <H1纳克绑定-HTML = “item.title”> </ H1>

  4. 不要使用$sce.trustAsHtml()



Answer 2:

我对这个解决方案是从这里下载js文件

http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js

我一直在使用一个我的角度混帐回购协议中,



Answer 3:

使用指令和解决方案没有使用“取代”的代码时遇到过这个问题。

`NG-HTML捆绑”正在上在templateUrl视图一个div使用

appDirectives.directive('helpText', [function () {
return {
    restrict: 'E',
    //replace: true, // With this uncommented it does not work!
    scope: {
        displayText: '='
    },
    templateUrl: '/web/form/helptext',
    link: function (scope) {

    }

};
}]);


Answer 4:

我的解决办法Seglespaan相反。 它是利用角消毒的鲍尔版本。

bower install angular-sanitize

https://github.com/angular/bower-angular-sanitize



Answer 5:

我遇到过类似问题,但我的是一个有点怪异。 而一切只包括输入代码并未呈现

<h3></h3>
<em></em> 

没有。 几个小时后,我意识到,除了

angular-sanitize.min.js 

我需要添加

textAngular-sanitize.min.js

我的项目之前,输入标签的工作。 这是很无奈,所以我希望这可以帮助任何人在类似的情况



文章来源: Angular sanitize / ng-bind-html not working?