javascript - How to call multiple functions in ng-keyup? - Stack Overflow

Edit: This is the crux of what I'm asking. Here's my html code:<input id="newTagInput

Edit: This is the crux of what I'm asking.

Here's my html code:

<input id="newTagInput" ng-keyup="$event.keyCode === 13 && vm.addTag() ; vm.toggleClick()">

When the user presses enter (keycode = 13) , I need to perform vm.addTag() and vm.toggleClick(). How do I do this? What is wrong with the syntax? I do not really understand the angular documentation on this.

Edit: This is the crux of what I'm asking.

Here's my html code:

<input id="newTagInput" ng-keyup="$event.keyCode === 13 && vm.addTag() ; vm.toggleClick()">

When the user presses enter (keycode = 13) , I need to perform vm.addTag() and vm.toggleClick(). How do I do this? What is wrong with the syntax? I do not really understand the angular documentation on this.

Share Improve this question edited Jun 13, 2016 at 14:29 McFiddlyWiddly asked Jun 13, 2016 at 1:02 McFiddlyWiddlyMcFiddlyWiddly 58110 silver badges32 bronze badges 5
  • 1 Why not just have a single wrapper function in place of vm.toggleClick(), that calls toggleClick() and whatever other functions you need to call. – ruby_newbie Commented Jun 13, 2016 at 1:05
  • From objective description I don't even see what you need ng-keyup for. Also you have vm.newTag as both a model and a function..... can't be both – charlietfl Commented Jun 13, 2016 at 1:13
  • ToggleClick() does something really simple, basically does this.clicked = !this.clicked. If that helps solve the particular problem. But I'm also looking for a general answer to the question, so that I can learn. – McFiddlyWiddly Commented Jun 13, 2016 at 1:27
  • The post is rather unclear. It would help if you extend the code the bit into an minimal reproducible example. Apart from a repro, some things in your text and question title are unclear too: you mix talking about clicks and key-up events. It's also a bit unclear why the question title subtly but importantly differs from the one-line question in the post body ("functions" vs "events"). Please review the post and edit to clarify. – Jeroen Commented Jun 13, 2016 at 5:42
  • @ruby_newbie Your solution works, but I was looking for a general answer to how to call multiple functions with ng-keyup, or if it was possible to do so. – McFiddlyWiddly Commented Jun 13, 2016 at 16:29
Add a ment  | 

1 Answer 1

Reset to default 6

To call multiple functions in an ng-keyup, you can wrap your desired functions in a ma separated array. Like so:

<input id="newTagInput" ng-keyup="$event.keyCode === 13 && [vm.addTag(), vm.toggleClick()]">

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418514a4626861.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信