AngularJS: Is ng-click “a good practice”? Why is there no ng-{event} in AngularJS?

Why is this one of the core concepts of AngularJS, if most people say this is “bad”?

Well, people who really like Unobtrusive JavaScript might say it is bad. Angularians (and those with a flex background) see value in the more declarative approach.

“Angular is built around the belief that declarative code is better than imperative when it comes to building UIs and wiring software components together… By declaratively describing how the UI should change as your application state changes, you are freed from low level DOM manipulation tasks. — Overview doc

See also Don’t the data attribute options used in Bootstrap, Angular.js, and Ember.js conflict with Unobtrusive Javascript principles?

what should I do with other DOM events?

Write your own directives to listen for them (or find one that someone else has already written). Angular gives you the power to extend what the browser can do — by writing your own directives.

Update: in the comments below, Tim Stewart mentions AngularUI’s ui-event, which lets you bind a callback to any event not natively supported by Angular.

Leave a Comment