关于angularjs:Angular清理/ ng-bind-html无法正常工作?

Angular sanitize / ng-bind-html not working?

我已经设置了一个中继器,只要其中没有html,就可以显示数据。

我包含了angular-sanitize.js,并尝试使用ng-bind-html

但是,在跨度中什么也没有显示,仅在ng-bind-html属性中显示。 所以看起来消毒没有用,

我读到,这需要添加到应用程序依赖项中,但不确定在哪里添加。

我刚刚在角度站点上进行了tut工作,因此目前仅设置了一个非常基本的控制器。


  • 您需要包含angular-sanitize.js
    http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js

  • 向您的模块依赖项添加" ngSanitize"

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

  • 不要在属性中使用{{}}

  • 不要使用$sce.trustAsHtml()


  • 我的解决方案是从这里下载js文件

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

    我一直在使用在角度git存储库中找到的那个,


    使用指令且解决方案未在代码中使用"替换"时遇到此问题。

    ng-html-bind已在templateUrl视图的div上使用

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    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) {

        }

    };
    }]);

    我遇到了类似的问题,但是我有点奇怪。仅输入标签未呈现,而其他所有内容(包括

    1
     

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

    1
    angular-sanitize.min.js

    我需要添加

    1
    textAngular-sanitize.min.js

    输入标签工作之前进入我的项目。这真的很令人沮丧,所以我希望这可以帮助处于类似情况的任何人


    我的解决方案与Seglespaan相反。它使用的是Bower版本的Angular Sanitize。

    1
    bower install angular-sanitize

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