输入中的ngBlur和该输入框中搜索的列表项目之间的问题

Problems between ngBlur in a input and the list items from a search in that input box

本文关键字:输入 项目 问题 列表 之间 ngBlur 搜索      更新时间:2023-09-26

我有一个带有输入标记的搜索框,然后是一个有序列表,其中包含用于输入文本搜索的选项。

输入已关联ngBlur指令,用于清除搜索框并关闭建议项目列表。

我的问题是,当我想点击一个项目时,它应该重定向到一个描述页面,但ngBlur首先检测到输入之外的事件并关闭所有内容。

<input class="search-box" ng-blur="closeSearch()">
<ul ng-repeat="product in products">
<li>{{product.name}}</li>
</ul>

结构就是这样的。有人能解决这个问题吗?

我不知道这是否是最好的方法,但我设法使用超时和布尔值处理ng模糊:

 $scope.stopPropagation = false;
  $scope.click = function() {
    alert("click");
    $scope.stopPropagation = true;
  }
  $scope.change = function() {
    $timeout(function() {
      if (!$scope.stopPropagation)
        $scope.filter = "asdasd";
      $scope.stopPropagation = false;
    }, 125);
  }

在这里,我把字符串"asdasd"放在函数更改中(由ng-flur激发),以不获得结果。我在125毫秒后应用更改,以便在删除列表中的数据之前激发单击功能。

链接:http://codepen.io/armellajuan/pen/qbNdVp