angular-ui / AngularJS-StyleGuide

Example of scalable architecture for my NG-Conf 2014 talk
http://www.youtube.com/watch?v=Iw-3qgG_ipU
284 stars 49 forks source link

How to provide custom behavior after calling model methods? #8

Closed szimek closed 10 years ago

szimek commented 10 years ago

Hey,

the idea of introducing model objects to Angular is pretty interesting and looks like it can significantly clean up controllers, but how do you handle results (custom code on success/failure like redirects and so on) from methods on such objects, e.g. in code like:

<form ng-submit="person.save()">
...
</form>

?

ProLoser commented 10 years ago

Theoretically you could place validation info on models or subscribe to server errors in the controller since your form should have validation built in but normally you are astute in that I more often than not throw a $scope.save() on the controller but it's usually no more than 2 or 4 lines

szimek commented 10 years ago

Thanks!