Tag angularjs

Good Advice on AngularJS

Angular.js has helped me understand what people when they describe a tool or framework as “opinionated”. Unlike Backbone, which, after you learn the importance of setters and getters, pretty much gets out of your way, Angular seems to have very specific expectations  for how you should do things. While working on our current project, my team spent the first couple of days marveling at how straightforward Angular seemed, and then another couple of days trying to understand why we couldn’t do anything that was a little more complex in a way that Angular liked.

More than any other piece of advice, Josh Miller’s Stack Overflow response to a question about thinking the ‘Angular way’ helped me out:

Don’t even use jQuery. Don’t even include it. It will hold you back. And when you come to a problem that you think you know how to solve in jQuery already, before you reach for the $, try to think about how to do it within the confines the AngularJS. If you don’t know, ask! 19 times out of 20, the best way to do it doesn’t need jQuery and to try to solve it with jQuery results in more work for you.

I had indeed been trying to do DOM manipulation with jQuery, and it was only after I took Josh’s advice to go completely without it that I started to make real progress with the problems I was trying to solve.

By the end of the week, I found myself ripping out large, chunks of HTML that I’d thought were too different to template, and making up for the differences with controllers and some carefully applied scoping.

I’m still a little vague on what constitutes just cause for moving something into a directive (can’t the same things be accomplished with partials and controllers?), but Angular seems to be sinking in.