如何使用 angular-ui 弹出框附加元素

How to append an element with angular-ui popover

我有一个函数可以将 div 附加到 table 中的每个单元格。您可以将其想象为每个单元格中带有 div 的 table。我通过以下方式做到这一点:

angular.element(document.getElementById()).append("<div>a</div>")

这绝对没问题。 但是,我需要这个附加的 div 才能在上面有一个弹出窗口。这不起作用:

em.append("<div popover='text' popover-trigger='mouseenter'>a</div>")

在我看来,popover 指令仅附加到页面呈现上的项目。之后添加的任何新项目都不会被指令跟踪。如何解决?

PS:如果我添加相同的 div 但直接在 html 模板中,弹出窗口就像一个魅力。

您需要使用 $compile 服务才能正常工作。如果你这样做,它应该工作:

em.append($compile("<div popover='text' popover-trigger='mouseenter'>a</div>")($scope));