【发布时间】:2016-04-15 03:53:05
【问题描述】:
在我的 AngularJS 控制器中,我调用我的数据服务方法,该方法调用 $http 来获取页面显示所需的数据。
appDataService.getById()
.success(function(document) {
vm.document = document;
}
.error(function(e)){});
一切都显示正常,我的大多数弹出框在切换/单击时都正确显示了它们的内容。但是,我遇到了其中一个问题。
<button popover-directive
popover-placement="auto"
popover-content="{{ vm.document.content }}"
popover-label="Click to View Text "
class="btn btn-info btn-xs">
</button>
我检查了 HTML 并且可以确认 popover-content 被赋予了正确的字符串值。但是,当我点击它时,并没有发生预期的触发弹出行为,
即没有出现新的<div class="popover fade right in">。
如果popover-content 被赋予一个直接值,例如popover-content="testing",则popover 可以正常工作并在单击时显示内容。
我强烈怀疑这是由于我的数据获取的异步行为所致;我的数据没有及时返回以使我的popover 正确初始化。
显然,我的 popover 指令正常运行,我认为问题不在于它,但为了完整起见,我提供以下 popover 指令:
function popoverDirective ($document) {
return {
restrict: 'A',
template: '<span>{{label}}</span>',
link: function (scope, element, attrs) {
scope.label = attrs.popoverLabel;
$(element).popover({
trigger: 'click',
html: true,
content: attrs.popoverContent,
placement: attrs.popoverPlacement
});
}
};
}
有什么解决办法吗?谢谢!
【问题讨论】:
标签: javascript jquery angularjs popover