Angular UI Bootstrap Popover 添加关闭按钮
Angular UI Bootstrap Popover adding a close button
我有以下弹出窗口并尝试添加一个关闭按钮以将其关闭。
.directive("popoverHtmlUnsafePopup", function () {
'use strict';
return {
restrict: "EA",
replace: true,
scope: { title: "@", content: "@", placement: "@", animation: "&", isOpen: "&", manualHide: '&' },
templateUrl: "views/popover/popover-html-unsafe-popup.html"
};
})
.directive("popoverHtmlUnsafe", [ '$compile', '$timeout', '$parse', '$window',"$tooltip", function ($compile, $timeout, $parse, $window, $tooltip) {
'use strict';
return $tooltip("popoverHtmlUnsafe", "popover", "click");
}]);
<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="arrow"></div>
<div class="popover-inner">
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
<div class="popover-content" bind-html-unsafe="content">
</div>
<button type="button" class="close" popover-trigger="close">×</button>
</div>
</div>
只是不确定要调用什么事件或函数
<button type="button" class="close" popover-trigger="close">×</button>
能够关闭弹出窗口
运行 在另一个使用工具提示的项目中遇到此问题。我最终遵循了 Tooltip.js
中的一些模式
通过使用 $compile 和新的子作用域,您可以根据自己的喜好自定义此弹出窗口。
.directive('popover2',['$parse', '$compile','$log','$templateCache','$position',
function ($parse,$compile,$log,$templateCache,$position ) {
function link(scope, element, attrs) {
var popupScope = scope.$new(false);
var html = $templateCache.get('views/popover/popover-html-unsafe-popup.html').trim();
var template = angular.element(html)
var popupLinkFn = $compile(template);
var popup = popupLinkFn(popupScope);
popupScope.isOpen = false;
popupScope.content = attrs['popover2'];
var position = function(){
var ttPosition = $position.positionElements(element, popup, scope.placement, false);
ttPosition.top += 'px';
ttPosition.left +='px';
popup.css(ttPosition);
};
popupScope.setOpen = function(val) {
popupScope.isOpen = val;
popup.css({display: popupScope.isOpen ? 'block' :'none' });
position();
// call twice, same as tooltip.js
position();
};
var cleanup = element.on('click',function(event){
popupScope.setOpen(!popupScope.isOpen);
});
element.after(popup);
element.on('$destroy',cleanup);
}
return {
replace:false,
link:link,
scope: {title: "@", placement: "@",},
};
}
]);
此指令将允许您显示基于按钮的弹出窗口,然后具有关闭功能。您可以根据需要扩展显示逻辑。我过去也成功地使用过有效的表格。
我有以下弹出窗口并尝试添加一个关闭按钮以将其关闭。
.directive("popoverHtmlUnsafePopup", function () {
'use strict';
return {
restrict: "EA",
replace: true,
scope: { title: "@", content: "@", placement: "@", animation: "&", isOpen: "&", manualHide: '&' },
templateUrl: "views/popover/popover-html-unsafe-popup.html"
};
})
.directive("popoverHtmlUnsafe", [ '$compile', '$timeout', '$parse', '$window',"$tooltip", function ($compile, $timeout, $parse, $window, $tooltip) {
'use strict';
return $tooltip("popoverHtmlUnsafe", "popover", "click");
}]);
<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="arrow"></div>
<div class="popover-inner">
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
<div class="popover-content" bind-html-unsafe="content">
</div>
<button type="button" class="close" popover-trigger="close">×</button>
</div>
</div>
只是不确定要调用什么事件或函数
<button type="button" class="close" popover-trigger="close">×</button>
能够关闭弹出窗口
运行 在另一个使用工具提示的项目中遇到此问题。我最终遵循了 Tooltip.js
中的一些模式通过使用 $compile 和新的子作用域,您可以根据自己的喜好自定义此弹出窗口。
.directive('popover2',['$parse', '$compile','$log','$templateCache','$position',
function ($parse,$compile,$log,$templateCache,$position ) {
function link(scope, element, attrs) {
var popupScope = scope.$new(false);
var html = $templateCache.get('views/popover/popover-html-unsafe-popup.html').trim();
var template = angular.element(html)
var popupLinkFn = $compile(template);
var popup = popupLinkFn(popupScope);
popupScope.isOpen = false;
popupScope.content = attrs['popover2'];
var position = function(){
var ttPosition = $position.positionElements(element, popup, scope.placement, false);
ttPosition.top += 'px';
ttPosition.left +='px';
popup.css(ttPosition);
};
popupScope.setOpen = function(val) {
popupScope.isOpen = val;
popup.css({display: popupScope.isOpen ? 'block' :'none' });
position();
// call twice, same as tooltip.js
position();
};
var cleanup = element.on('click',function(event){
popupScope.setOpen(!popupScope.isOpen);
});
element.after(popup);
element.on('$destroy',cleanup);
}
return {
replace:false,
link:link,
scope: {title: "@", placement: "@",},
};
}
]);
此指令将允许您显示基于按钮的弹出窗口,然后具有关闭功能。您可以根据需要扩展显示逻辑。我过去也成功地使用过有效的表格。