简体   繁体   English

Angular:输入失去焦点后,下拉菜单关闭太快

[英]Angular: Dropdown menu closes too quickly after input loses focus

I'm trying to build a search input with a dropdown menu attached to it. 我正在尝试使用附加的下拉菜单构建搜索输入。 I have set the menu to close when the input box loses focus. 当输入框失去焦点时,我已将菜单设置为关闭。

Problem: When I click on the links inside the dropdown menu, the menu closes even before any events are registered. 问题:当我点击下拉菜单中的链接时,即使在注册任何事件之前菜单也会关闭。

// Search input box
<input type="text" ng-blur="lostFocus()" eva-search />

// Dropdown menu
<div class="component-styleWrap"
     ng-click="$event.stopImmediatePropagation(); $event.stopPropagation()">
  <li>Example Link</li>
  <li>Example Link</li>
</div>

If you just want to delay the effects of your call to lostFocus(), then a timeout should be enough. 如果你只想延迟调用lostFocus()的效果,那么超时就足够了。

app.controller("myController", function ($scope,  $timeout) {
    $scope.lostFocus = function () {
        $timeout(function () {
            //whatever your code needs to do goes here.
        }, 100);
     });
});

You shouldn't really need the 100 in there. 你不应该真的需要那里的100。 I just added that to be on the safe side. 我刚才补充说,为了安全起见。 Try it without the 100 if you can. 如果可以,请尝试不使用100。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM