0

I use to bind keyup on all input elements in jQuery like this:

$("input[type='text']").keyup(doSomething);

How can I do this from inside angular controller? I do not want to write ng-keyup on every input element.

Ashutosh
  • 4,371
  • 10
  • 59
  • 105
  • This seems not be like an Angular 2/4 that you are asking. If so will you please update the tag with `angularjs` instead of `angular`. As [angular](https://stackoverflow.com/tags/angular/info) is for Angular2/4 while `angularjs` is for Angular 1.x. – The Hungry Dictator Jul 31 '17 at 04:50
  • Possible duplicate of [Bind function on key up in Angular](https://stackoverflow.com/questions/34052939/bind-function-on-key-up-in-angular) – Adrian Aug 01 '17 at 15:21

1 Answers1

0

Edit: This question was original with Angular 2 tag, So the Answer has Angular 2 reference. I'll delete this answer, since this is no longer valid.

Don't use jQuery in Angular 2 applications. Although you can use that but it is highly discouraged. There is an Angular way to bind the events. i.e. in view:

<button (keyup)="foo($event)"> 

in component:

foo(event) {
  console.log(event.target);
}

Source: Angular Cheat Sheet

Malik Shahzad
  • 6,703
  • 3
  • 37
  • 49