In creating controllers, I have adopted an "orthodox" technique like the 
one recently discussed here: The "Dot" in the model 
<https://groups.google.com/forum/#!topic/angular/zAjgjeyWptI>.

A nice byproduct (I think) of the "always use a view-model" approach is 
that these models can easily be extended, either prototypically or 
mixin-style, via methods on an "extender" or "mixer" service.  

So far, I have really profited from the mixin service approach, extending 
my view-models to give them a set of standard behaviors (i.e. properties 
and methods) relevant to common business needs:

   - Paged lists
   - Entry forms
   - Sub-navigation (i.e. "nested views")
   - Configurable toolbars

But wait: can't we implement those sorts of behaviors via directives?  Of 
course we can.  But extending a controller's view-model (I think) is both 
simpler and more flexible.  Here is why:

   1. Members can be more easily shared (i.e. you don't need to worry about 
   binding, isolate scopes, etc. that come with directives)
   2. You don't need to commit to a directive's UI
   3. It's just simple OOP -- your logic isn't married to view-models (or 
   even Angular, for that matter), in case you want to use it elsewhere; it 
   can also be more easily tested for this reason

I know this is fairly very abstract, but I would like to ask the group:

   - What do you think of this approach?
   - If you are doing something similar, how have you chosen to implement 
   it?
   - What are some common patterns of controller behavior that could be 
   implemented neatly with this technique?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to