【发布时间】:2013-11-28 13:54:04
【问题描述】:
我有以下代码用于在我的模板文件中创建弹出框:
<span class="icon-globe visibility"
id="visibilityFor{{post.metaData.assetId}}"
popover="{{post.visibilityListStr}}"
popover-placement="right"
popover-trigger="mouseenter"
popover-popup-delay="50"
visibility>
</span>
我在弹出框上有一些可点击的链接。但问题是我无法将鼠标悬停在创建的弹出框上。我参考了链接http://jsfiddle.net/xZxkq/ 并试图创建一个指令,即。用于此目的的“可见性”。
代码如下:
myAppModule.directive("visibility", function ($timeout,$rootScope) {
return {
controller: function ($scope, $element) {
$scope.attachEvents = function (element) {
$('.popover').on('mouseenter', function () {
$rootScope.insidePopover = true;
});
$('.popover').on('mouseleave', function () {
$rootScope.insidePopover = false;
$(element).popover('hide');
});
}
},
link: function (scope, element, attrs) {
$rootScope.insidePopover = false;
element.bind('mouseenter', function (e) {
$timeout(function () {
if (!$rootScope.insidePopover) {
element.popover('show');
attachEvents(element);
}
}, 200);
});
element.bind('mouseout', function (e) {
$timeout(function () {
if (!$rootScope.insidePopover) {
element.popover('show');
attachEvents(element);
}
}, 200);
});
}
}
});
但我得到了“element.popover”的异常,因为它是未定义的。请指出我做错了什么以及如何从指令中显示/隐藏角度 ui 弹出框。我正在使用 angular ui bootstrap JS 文件。
【问题讨论】:
标签: angularjs angularjs-directive angular-ui angular-ui-bootstrap