dimanche 1 mars 2015

AngularJS and models

I have been writing some AngularJS stuff on and off now. The pattern I tend to follow focuses particularly on ensuring that I have controllers handling UI manipulation with an underlying service (i.e. user service) that is responsible for fetching data, performing validations (when a user form is being submitted) and resolving or rejecting a promise that it returns, etc. etc.


What I am not sure about is the use of dedicated models. For example, when writing Java, C#, or even Objective C, we use dedicated models (think of POJO's or POCO's or the models generated by Core Data in the iOS realm).


In AngularJS, is this something that's encouraged? For example, in my controller I have a user object in my scope and in the view I have input fields, drop downs, etc. (i.e. user.first_name, user.last_name, user.date_of_birth, etc. etc.). Is the recommended pattern to create a factory object that holds a user dictionary that explicitly defines these fields and sets each value to an empty string (i.e. user.first_name = "";) by default?


Aucun commentaire:

Enregistrer un commentaire