繁体   English   中英

AngularJS ng-bind-html

[英]AngularJS ng-bind-html

这是我在Angular中使用的过滤器,我只显示了该应用程序的摘录。 这可以在一个控制器中工作,但是当我尝试在另一个控制器中使用它却没有。

我的意思是不起作用-它不会在DOM内部呈现。 虽然它呈现在标签内部。

AngularJS: <h2 ng-bind-html="'{{ answer.title }}' | to_trusted"></h2>

示例呈现<h2 ng-bind-html="'0-60 minutes per week' | to_trusted" class="ng-binding"></h2>

AngularJS过滤器

    .filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);
        };
    }])

我在这里偶然错过了什么吗?

我认为使这种语法对您answer.title是,因为answer.title已经是文本了:

<h2 ng-bind-html="answer.title | to_trusted"></h2>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM