gpt4 book ai didi

angularjs - Angular UI Bootstrap Popover 添加关闭按钮

转载 作者:行者123 更新时间:2023-12-02 22:22:27 24 4
gpt4 key购买 nike

我有以下弹出窗口,并尝试添加一个关闭按钮以将其关闭。

.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">&times;</button>
</div>
</div>

只是不确定要调用什么事件或函数

<button type="button" class="close" popover-trigger="close">&times;</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: "@",},
};
}
]);

JSFiddle

该指令将允许您显示基于按钮的弹出窗口,然后具有关闭功能。您可以按照您认为合适的方式扩展显示逻辑。我过去也成功地使用过有效的表单。

关于angularjs - Angular UI Bootstrap Popover 添加关闭按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28298107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com