[caption id="attachment_4953" align="alignnone" width="640"]

Another sort of rich model[/caption]
Angular.js is deliberately un-opinionated about how you should structure your data models. Whilst it lays out very clear guidelines for directives, controllers and services, it also makes a selling-point of the fact that it can bind to plain-old Javascript objects with plain-old properties.
Services are singletons, so it can be unclear as to if and how you can group per-object state and behaviours. Consequently, people tend to fall back to services that deal in very simple JSON objects - i.e. objects that contain only data, not behaviour. However, building the sorts of rich interfaces that our users demand means that we sometimes need to more fully leverage the MVC pattern. Put differently, for some problems it can be useful to have a rich object model that provides both data
and behaviour.
Recently at
ng-conf, I
presented a simple approach I've used for using rich object models with Angular.js. This technique leverages existing frameworks, maintains testability, and opens up a range of possibilities for more succinct and easy-to-understand code. In this post I'll outline the underlying approach, but you can also find some (very simple) helper code
here.
04 February, 2014
/