Angular消毒/ng绑定html不工作



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

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

但是在跨度内不显示任何内容,仅在ng-bind-html属性内显示。所以看起来消毒不起作用,

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

我刚刚在角度网站上完成了教程,所以现在只设置了一个非常基本的控制器。

  1. 你需要包含angular-splicate.jshttp://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js

  2. 将"ngSanitize"添加到模块依赖

    var myApp=角度模块('myApp',['ngSanitize']);

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

    <h1 ng bind html="item.title">lt/h1>

  4. 不使用$sce.trustAsHtml()

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

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

我一直在使用我在angular git repo中发现的

我遇到了类似的问题,但我的问题有点奇怪。只有输入标签没有呈现,而包括在内的所有其他内容都没有呈现

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

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

angular-sanitize.min.js 

我需要添加

textAngular-sanitize.min.js

在输入标记工作之前,将其添加到我的项目中。这真的很令人沮丧,所以我希望这能帮助任何处于类似情况的人

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

`"ng html bind"正在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) {
    }
};
}]);

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

bower install angular-sanitize

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

最新更新