【发布时间】:2016-07-05 13:59:37
【问题描述】:
我有一个弹出框作为自定义指令,当单击或悬停在图标上时会打开。单击图标时,弹出框会粘住,如果再次单击该图标,它将关闭。现在我想通过单击弹出框以外的任何其他位置来关闭弹出框。下面是我的代码...
我的自定义指令
(function () {
'use strict';
angular.module('frontend.core.directives')
.directive('myPopover', [
function directive() {
return {
restrict: 'E',
templateUrl: '/frontend/core/directives/my-popover/my-popover.html',
scope: {
trigger: '@',
title:'@'
},
transclude: true,
link: function (scope, elm, attrs) {
//Need to hide content first
elm.hide();
//plugin binder
$(scope.trigger).popover({
html: true,
trigger: 'hover click',
placement: 'auto',
content: function () {
return elm.html();
},
title: function () {
return scope.title;
}
});
}
};
}
]);
}());
我的 HTML
<div>
<i id="touch-details" class="fa fa-info-circle"></i>
<my-popover trigger="#touch-details" my-popover-trigger="outsideClick" title="Details">
<span>
Inside of my popover
</span>
</my-popover>
</div>
请告诉我我需要做什么才能在外部单击时关闭弹出框。
【问题讨论】:
-
如果您的弹出框后面有某种覆盖,您可以随时检查该覆盖是否已被点击。类似:
overlay.on('click', function() {myPopover.close();});在你的指令中
标签: javascript angularjs twitter-bootstrap popover using-directives