【发布时间】:2015-04-13 17:25:50
【问题描述】:
为了获得这种能力,我扩展了工具提示提供程序。
function customTooltip($document, $tooltip) {
var tooltip = $tooltip('customTooltip', 'customTooltip', 'click'),
parentCompile = angular.copy(tooltip.compile);
tooltip.compile = function (element, attrs) {
var parentLink = parentCompile(element, attrs);
return function postLink(scope, element, attrs) {
var firstTime = true;
parentLink(scope, element, attrs);
var onDocumentClick = function () {
if (firstTime) {
firstTime = false;
} else {
element.triggerHandler('documentClick');
}
};
var bindDocumentClick = function () {
$document.on('click', onDocumentClick);
};
var unbindDocumentClick = function () {
$document.off('click', onDocumentClick);
};
scope.$watch('tt_isOpen', function (newValue) {
firstTime = true;
if (newValue) {
bindDocumentClick();
} else {
unbindDocumentClick();
}
});
scope.$on('$destroy', function onTooltipDestroy() {
unbindDocumentClick();
});
};
};
return tooltip;
}
但是这种方法已经不起作用了,因为现在范围内没有 tt_isOpen 属性。实际上我看不到任何工具提示属性,只有我的父范围。我猜这是因为 tooltip.js 124 行 https://github.com/angular-ui/bootstrap/blob/master/src/tooltip/tooltip.js#L124 的变化而发生的。现在有什么方法可以通过在工具提示外部单击或至少获取 isOpen 标志来关闭工具提示?
【问题讨论】:
标签: javascript angularjs angular-ui angular-ui-bootstrap