弹出窗口内容无法使用angularjs ng-click

时间:2022-10-22 09:11:19

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.

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

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.

我要做的是简单地在bootstrap pop-over中放一个按钮,调用我创建的指令范围内的函数。问题是使用jquery来获取内容它不起作用,因为范围似乎在外面。还试图在函数内部创建内容它将无法工作,因为它将不会被编译。

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

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

$("#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/

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

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

以下是我的Dropbox上的工作示例:https://dl.dropboxusercontent.com/u/19470623/hatethis/test.html

1 个解决方案

#1


5  

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

有2个问题,你的小提琴中没有包括ngRoute,你需要编译popover中返回的内容。

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

Also you do not need the timeout.

你也不需要超时。

Example: Plunker

示例:Plunker

#1


5  

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

有2个问题,你的小提琴中没有包括ngRoute,你需要编译popover中返回的内容。

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

Also you do not need the timeout.

你也不需要超时。

Example: Plunker

示例:Plunker