如何在 Angular JS 中使用搜索按钮和键盘上的 Enter 按钮触发功能?

How to fire a function with Search button as well as the Enter button on keyboard in Angular JS?

我有一个搜索字段,当在该字段中输入文本后单击搜索按钮时,该字段当前会触发。代码如下:

<div class="form-group">
  <input type="text" class="form-control" id="Search" ng-model="searchkey">
</div>
<button type="submit" ng-click="searchfunc(searchkey)">
  Search
</button>

如何通过键盘上的 Enter 键以及在“搜索”字段中输入内容时触发此搜索?

HTML:

<input type="text" class="form-control" id="Search" ng-model="searchkey" ng-keydown="myFunc($event)">

控制器:

$scope.myFunc = function(keyEvent) {
  if (keyEvent.which === 13) {
    // do stuff
    // here you can call the function and pass a parameter: "searchfunc($scope.searchkey);"
  }
}

这是工作示例:http://jsfiddle.net/Sj4ZU/62/