Angularjs 角度UI引导工具提示工具提示是打开的

Angularjs 角度UI引导工具提示工具提示是打开的,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,我在自己的指令中使用Angular UI引导中的工具提示指令。我想使用引导工具提示提供的tooltip is open属性手动切换工具提示的可见性。国家: 指令链接功能 module(...).directive(..., function() { return { link: function(scope, elem, attr) { /* Stop further propagation of event */ func

我在自己的指令中使用Angular UI引导中的工具提示指令。我想使用引导工具提示提供的
tooltip is open
属性手动切换工具提示的可见性。国家:

指令链接功能

module(...).directive(..., function() {
    return {
        link: function(scope, elem, attr) {
            /* Stop further propagation of event */
            function catchEvent(event) {
                event.stopPropagation();
            };

            function showTooltip(event) {
                scope.$apply(function() {
                    scope.tooltipIsOpened = true;

                    /* Hide tooltip on any click outside the select */
                    angular.element(document).on('click', hideTooltip);
                    elem.on('click', catchEvent);
                });
            };

            function hideTooltip() {
                scope.$apply(function() {
                    scope.tooltipIsOpened = false;

                    /* Remove previously attached handlers */
                    angular.element(document).off('click', hideTooltip);
                    elem.off('click', catchEvent);
                });
           };

           scope.tooltipIsOpened = false;

           elem.on('mouseenter', showTooltip);
           elem.on('mouseleave', hideTooltip);
        });

第1种方式不正确,因为此指令要求的是变量名,而不是变量值。如此正确:

<div uib-tooltip="Tooltip message" tooltip-is-open="xxx">

或更正(传递{{}},但传递的不是变量的值,而是存储变量名的变量的值):


第二种方式在某种程度上起作用: 但这是非常奇怪的-用户如何在不触发mouseleave事件的情况下单击外部元素

问题是你不需要这些,只要:

<button uib-tooltip="Tooltip message" trigger="mouseenter"
     tooltip-is-open="tooltipIsOpened">
   hello
</button>

你好
很好


第三种方法:如果您看到“open”不起作用,但“smth.open”起作用,这通常意味着您面临“点问题”——您不能直接从子范围更改父范围变量,但可以更改变量属性。关于这个问题,有很多例子和解释。

关于你给出的链接上的toggleTooltip例子呢?第一种方式不正确,第二种方式应该在单击中使用apply,而不是在注册事件时使用。@PetrAveryanov:为什么第一种方式不正确?为什么说我应该在第二种方法中使用
$apply()
内部
单击
?它仅在
点击
处理程序
hideTooltip()
中使用。您想知道用户如何能够在不首先触发
鼠标移动的情况下点击元素外部。这在我的应用程序中是可能的,因为元素(我将其简化为
,以使这个示例更清晰)是一个带有下拉菜单的选择组件。单击下拉菜单中的元素后,它将消失,并且您不触发
mouseleave
,就在select元素之外。您能给我一些有关角度观察者的“点问题”的示例吗?在上一个示例中,什么是
trigger
属性?trigger
属性做什么?
<div uib-tooltip="Tooltip message" tooltip-is-open="xxx">
<div ng-init="yyy='xxx'">
    <div uib-tooltip="Tooltip message" tooltip-is-open="{{yyy}}">
<button uib-tooltip="Tooltip message" trigger="mouseenter"
     tooltip-is-open="tooltipIsOpened">
   hello
</button>