添加NG-click事件的过滤器内部 [英] Adding an ng-click event inside a filter

查看:352
本文介绍了添加NG-click事件的过滤器内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的角度,但我一直在使用它了过去几个星期,并已成功地制定出大多数我遇到的问题。这其中有但我难住了。

I'm fairly new to Angular but I've been using it the past few weeks and have managed to work out most of the problems I've come across. This one however has me stumped.

我在Twitter的鸣叫,然后拉一个应用程序 - 使用角度滤波器 - 翻出所有的URL和款式它们作为链接。这部分工作正常,但在客户端决定,从Twitter的链接were't安全因此他们想免责声明火是每点击一个链接时。很简单 - 我被劫持的联系,并交换了的href NG-点击=OpenLink公司(URL),。这是问题发生的位置 - 在 NG-点击不起作用

I have an app that pulls in tweets from Twitter then - using an angular filter - pulls out all the urls and styles them as links. This part works fine but the client decided that links from Twitter were't safe so they wanted a disclaimer to fire every time a link was clicked. Simple enough - I hijacked the link and swapped the href for an ng-click="openLink('url')". This is where the problem occurred - the ng-click doesn't work.

我是pretty确保问题有一些与 $做编译() - 我以前也有类似的问题 - 但我不知道什么时候或者调用它。

I'm pretty sure the problem has something to do with $compile() - I've had similar issues before - but I have no idea when or where to call it.

我创建了一个 Plunkr 这是我后一个精简版的版本。顶部的链接不加载动态,并触发 alertUrl()功能很好,但全部由过滤器生成的链接失败。

I've created a Plunkr that is a lite version of what I'm after. The link at the top isn't loaded in dynamically and fires the alertUrl() function fine, but all the links generated by the filter fail.

我可能失去了一些东西很简单,但它现在已经缠着我了一会儿所以任何帮助将是大量AP preciated。

I'm probably missing something really simple but it's been bugging me a while now so any help will be massively appreciated.

谢谢,结果
山姆

Thanks,
Sam

推荐答案

那么你是正确的,你发出的需求HTML \\内容编译为angularjs解决报警功能。

Well you are correct that the html\content that you emit needs to be compiled for angularjs to resolve the alert function.

我已经改变了你的plunker,并注入编译指令(从这里

I have changed your plunker, and inject a compile directive (from here)

请参阅它这里行动

See it in action here

这里的基本思想是汇编从动态叽叽喳喳饲料生产的内容

The basic idea here is to compile the content produced from twitter feed dynamically.

<p compile="tweet.text | convertLinks"></p>

这篇关于添加NG-click事件的过滤器内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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