链接在ng-bind-html中不起作用 [英] Links not working in ng-bind-html

查看:282
本文介绍了链接在ng-bind-html中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ng-bind-html,但是绑定html中的链接不起作用.

I am using ng-bind-html but the links in the to binding html won't work.

这是绑定内容的代码:

<div class="list-group-item-text" ng-class="article.img.length >0 ? 'col-md-10' : 'col-md-12'"
                 ng-bind-html="article.content | to_trusted">
</div>

这是链接的编译方式

This is how the link gets compiled

to_trusted过滤器如下所示:

the to_trusted filter looks like this:

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

而且,当我单击链接时,没有任何反应.控制台中什么也没有.

and still, when I click on the link nothing happens. Nothing in the console neither.

想法?

输入字符串:

It was never really finished and is actually in a state which is a result of playing around with jQuery and other tools. <a href="http://www.google.com" target="_blank">Google</a>

Edit2:我应该说,如果我右键单击该链接,然后单击在新选项卡中打开",则该链接将完全正常工作

I should say, the link works completely fine if I right-click it and then click "open in a new tab"

推荐答案

答案实际上非常简单而且令人尴尬.

The answer is actually quite easy and embarassing.

我将<a> </a>包裹在呈现ng-bind-html的容器周围.将其更改为div.显然,现在一切正常.

I had an <a> </a> wrapped around the container where the ng-bind-html got rendered. Changed it to a div. Obviously everything works now.

这篇关于链接在ng-bind-html中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆