在AngularJS中关闭Twitter键入Enter键

时间:2014-10-17 15:37:39

标签: angularjs twitter-typeahead

我使用Twitter typeahead Angular directive使用搜索字段

当我点击 Enter (即没有选择任何建议时),我无法弄明白如何关闭 提前建议 。有人可以帮帮我吗?

当按下 Enter 时,我可以通过separate directive触发搜索,但我不知道如何关闭这些建议。

我在运行搜索时可以使用此hack:

jQuery('.tt-dropdown-menu').hide();
jQuery('.tt-hint').hide();

jQuery('.tt-hint').show();在其他按键上,但必须有更合适的方式。

1 个答案:

答案 0 :(得分:2)

您可以将typeahead放在表单中并添加display: none提交按钮

 <form novalidate>
      <input type="text"             
             ng-model="myModel"
             typeahead="something.value for something in myList" />
      <input type="submit" value="Submit" style="display: none">
</form>

当你点击

时会关闭typeahead指令
相关问题