我有一个简单的bootstrap popover,当我点击一个按钮时会打开。我想使用某种循环来显示弹出框体中的名称列表。我有我的angularjs控制器中的名称列表。我在popover中使用ng-repeat来建立列表。 ng-repeat运行良好,如果我在popover之外使用它,但它似乎在popover主体中不能正常工作。ng-repeat在bootstrap popover中无法正常工作
它似乎表现得好像我的代码中有2级嵌套的ng-repeat,尽管我没有在任何地方嵌套ng-repeat!此外,弹出窗口似乎不会从正确的位置“弹出”(它应该从按钮弹出)。难道我做错了什么?提前致谢!这里是fiddle
这里是我的显示酥料饼代码:
$scope.showPopover = function() {
jQuery(function($) {
$('#pop').popover({
html: true,
container: 'body',
title: '<b style="margin-top:5px">Some Title</b> '+
'<button type="button" id="popoverCloseButton" class="close">×</button>',
content: function() {
return $compile($('#popover_content').html())($scope);
},
placement: 'auto right'
}).popover('show');
document.getElementById("popoverCloseButton").addEventListener("click", function(){
$scope.destroyPopover();
});
});
};
谢谢@sourdoughdetzel的答案。如果我在$ compile(...)中将模板写成字符串,ng-repeat肯定会起作用。但是,这不是你刚才提到的最好的方式。我希望有人能向我们解释为什么会发生这种情况。 –
有人可能会认为将html字符串存储在控制器中比将其隐藏在DOM中更好。 – sourdoughdetzel