Wednesday, February 27, 2013

Initial reaction to element based directives and to root scoped examples

I don't like the idea of creating new 'E' element directives, simply because it makes it harder for a dev to later look at your code and know that your <custom-shit> tag is being manipulated from Angular. <div data-ng-custom-shit> seems a lot more self-explanatory.

Also, in a lot of examples, I'm seeing functions being defined in the root scope. This may be fine for a single page app, but if your code exists in a complex multi-page site, it would be cleaner to namespace functions like:

customNgNamespace = customNgNamespace || {};
customNgNamespace.customFunction = function(){/*...stuff...*/}

about 5 hours in...

I've been reading a lot about Angular and it's getting a lot of good press as a powerful MVC framework. I've done one project using Backbone.js, and another with Knockout, so I'm relatively comfortable with JavaScript development, and the high-level MVC concepts involved. That said, it's disheartening to come across beginner posts that warn you about the state of the documentation.  Luckily, the Angular Google-group seem to be a good source of information and advice.

My company is switching to an Angular model from a jQuery paradigm, so I've got a lot of learning to do in a short time, and Angular is proving to have a bit of a learning curve.  The following is a reference collection of tips and notes that didn't at first seem obvious. The advice I've gotten from devs coming from jQuery background is to (at first) omit jQuery from your development process. It competes with the flexibility of the Angular paradigm, and will cause testing headaches later.