gpt4 book ai didi

html - 如何在 ng-blur 之前调用 ng-click?

转载 作者:可可西里 更新时间:2023-11-01 13:04:21 27 4
gpt4 key购买 nike

我创建了一个文本输入,在输入时会出现一些建议(就像在 Google 上一样 - 你正在写一些东西,它会建议你一些文本)。

<input id="smartBar" ng-focus="showSuggestions=true" ng-blur="showSuggestions=false" ng-model="smartBar" ng-keydown="smartBarKeyDown($event)" focus-on="smartBar" />
<table class="suggestionList" ng-show="showSuggestions">
<tr ng-repeat="sg in suggestions" ng-class="{highlighedSuggestion: $index == highlightedSuggestion}" ng-click="suggestionClicked($index)">
<td ng-repeat="nt in sg.NoteTags" style="padding: 0rem 1rem">
{{nt.Tag.Name}}
</td>
</tr>
</table>

我想增加点击“建议”之一的可能性(< TR> html 属性中有 ng-click 属性)。不幸的是,ng-blur 似乎比 ng-click 更早工作,所以当我点击其中一个选项时,输入失去焦点并且 suggestionList 在检测到点击之前变得不可见。

如何在隐藏 suggestionList 之前检测点击?

最佳答案

你不能。但是,您可以使用 ngMousedown 而不是 ngClick 来实现所需的功能:

HTML:

ng-mousedown="suggestionClicked($index, $event)

JS:

$scope.suggestionClicked = function(index, evt) {
//detect left click
if(evt.which === 1) {
//your code
}
}

关于html - 如何在 ng-blur 之前调用 ng-click?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34829234/

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