我正在使用bs-popover在angularjs中單擊(作爲菜單)來顯示我的內容。但是當我點擊瀏覽器窗口中的某個地方時,我需要隱藏這個彈出式菜單。我希望在這種事件中被解僱。我怎樣才能做到這一點?如何根據事件隱藏bs-popover
0
A
回答
1
您需要爲此編寫指令。
yourApp.directive('bndocumentclick',
function($document,$rootScope,$timeout) {
return {
restrict: 'EA',
link : function(scope, element, attrs) {
$document.on("click", function(ev) {
// Do stuff here to remove your popover.
}
}
}
});
HTML
<body bndocumentclick>
而且
<div bs-popover ng-click="$event.stopPropagation()">
您需要使用,因爲你不希望關閉酥料餅只要裏面酥料餅的用戶點擊。
0
由@Jay Shukla提供的解決方案不起作用。
觸發彈出窗口的元素上的「$ event.stopPropagation()」不會阻止它在彈出窗口內進行單擊時關閉它。如果在彈出窗口中有一些交互,這將是一個問題。
這工作:
angular.module('yourApp')
.directive('closePopovers', function ($document, $rootScope, $timeout) {
return {
restrict: 'EA',
link: function (scope, element, attrs) {
$document.on('click', function (ev) {
var targetElem = angular.element(ev.target);
if (targetElem.data('toggle') !== 'popover'
&& targetElem.parents('[data-toggle="popover"]').length === 0
&& targetElem.parents('.popover').length === 0) {
$('.popover').each(function() {
var $this = $(this);
var scope = $this.scope();
scope.$apply(function() {
scope.$hide();
});
}
);
}
});
}
};
});
對你的身體:
在你的元素觸發酥料餅:
<button data-toggle="popover" [other data elements here] bs-popover>Toggle popover</button>
相關問題
- 1. 在Angular2中,如何根據組件中收到的事件隱藏組件?
- 2. 根據條件隱藏控件集合
- 3. 如何根據數據庫條件使用vbscript來隱藏div?
- 4. 根據外部事件顯示/隱藏標記
- 5. 如何根據wpf中的按鈕單擊事件關閉/隱藏框架?
- 6. 根據選定的值隱藏控件
- 7. KeyBoard隱藏事件
- 8. 隱藏ProgressChanged事件
- 9. 根據日期隱藏行
- 10. JQuery根據天隱藏div
- 11. 根據網址隱藏div
- 12. 隱藏按鈕根據組
- 13. 如何捕獲CodeMirror隱藏/取消隱藏事件?
- 14. 如何根據條件隱藏Gridview特定位置
- 15. 如何根據wpf中的條件檢查來隱藏字段?
- 16. Sitecore:如何根據條件顯示或隱藏某些頁面?
- 17. 如何根據odoo10中的複雜條件隱藏字段?
- 18. 如何根據條件在grails中顯示和隱藏按鈕?
- 19. 如何根據條件隱藏標題模板?
- 20. 如何根據特定條件隱藏jQuery中的行?
- 21. Datatables:根據數據庫值隱藏列
- 22. repositoryitemhyperlinkedit根據行數據顯示/隱藏
- 23. ShinyBS bsPopover和updateSelectInput
- 24. Facebox 1.2隱藏事件?
- 25. 停止隱藏事件
- 26. 隱藏的iframe onload事件
- 27. 更改隱藏事件
- 28. 事件在代碼隱藏
- 29. 窗體在隱藏事件
- 30. 鍵盤隱藏事件
'BS-popover'意味着Twitter的引導酥料餅? – callmekatootie
是的。它從引導 – anilCSE
我的答案將爲你工作。 :) –