我有一個彈出式窗口作爲自定義指令,當單擊或懸停圖標時打開。點擊圖標後,彈出窗口會粘住,如果再次單擊該圖標,將關閉。現在,我想通過單擊其他任何位置(但彈出窗口)來關閉彈出窗口。下面是我的代碼...使用outsideClick關閉自定義指令彈出框
我的自定義DIRECTIVE
(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();});'在你的指令中 –