Fire button click in AngularJS

橙三吉。 提交于 2019-12-03 14:36:30

This took me a while to figure out (lots of fiddles).

<form id="nowsorting" ng-submit="getData(sc_user)">Now sorting the Soundcloud likes of <input type="text" ng-model="sc_user"><input type="submit" value="Sort"></form>

Make a form and use ng-submit to fire the event (likely a function).

Then create two inputs (one is "text" and the other "submit").

Then pushing enter should fire the ng-submit event/function.

You mentioned

fire a button's click event when pressing ENTER inside a input

So if it is safe to assume that you can have a form I would prefer using ng-submit as shown below.

<form ng-submit="clickEventFunction()">
  <input type="text"/>
  <button type="submit">Click</button>
</form>

Note button type should be submit.

bfcamara

I think, you just have to call your $scope.onButtonClick()

Please check this Plunker

$scope.onKeyPress = function($event) {
   if ($event.keyCode == 13) {
      $scope.onButtonClick();
   }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!