弹出内容不适用于angularjs ng-click [英] Popover content not working with angularjs ng-click

查看:24
本文介绍了弹出内容不适用于angularjs ng-click的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了所有关于此的帖子,但不幸的是它们都没有帮助:jsfiddle 和 plunker 链接似乎不再有效.

我想要做的是简单地在引导弹出窗口中放置一个按钮,该按钮调用我创建的指令范围内的函数.问题是使用 jquery 来抓取它不起作用的内容,因为范围似乎在外面.还试图在函数内部创建内容它不会工作,因为它不会被编译.

我在 jsfiddle 上创建了一个示例,但不知何故 angularjs 没有加载到正确的位置,因此它也不起作用.

$("#pop-over-link").popover({'位置':'顶部','触发器':'点击','html':真的,'容器':'身体','内容':函数(){返回 $("#pop-over-content").html();}});

这是打开弹出窗口、抓取内容并显示它的一段代码.

这里是jsfiddle:http://jsfiddle.net/75zLT/2/

这是我的保管箱上的工作示例:https://dl.dropboxusercontent.com/u/19470623/hatethis/test.html

解决方案

有 2 个问题您没有在 fiddle 中包含 ngRoute,并且需要编译 popover 中返回的内容.

'content': function() {返回 $compile($("#pop-over-content").html())(scope);}

你也不需要超时.

示例:Plunker

I have already read all the posts about this, but unfortunately none of them was helpful: jsfiddle and plunker links appear to be no longer working.

What I am trying to do is to simply put a button inside the bootstrap pop-over which makes a call to a function inside the scope of the directive I've created. The problem is that using jquery to grab the content it does not work since the scope appear to be outside. Also trying to create the content inside the function it won't work because it will be not compiled.

I created an example on jsfiddle, but somehow angularjs is not loaded in the right point and therefore it doesn't work either.

$("#pop-over-link").popover({
      'placement': 'top',
      'trigger': 'click',
      'html': true,
      'container': 'body',
      'content': function() {
           return $("#pop-over-content").html();
      }
});

This is the piece of code that opens the pop over, grabs the contents and shows it.

Here the jsfiddle: http://jsfiddle.net/75zLT/2/

And here is the working example on my dropbox: https://dl.dropboxusercontent.com/u/19470623/hatethis/test.html

解决方案

There were 2 issues your were not including ngRoute in your fiddle and your need to compile the content returned in the popover.

'content': function() {
     return $compile($("#pop-over-content").html())(scope);
 }

Also you do not need the timeout.

Example: Plunker

这篇关于弹出内容不适用于angularjs ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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