Popover content not working with angularjs ng-click

China☆狼群 提交于 2019-12-25 02:38:38

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/21205250/popover-content-not-working-with-angularjs-ng-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!