4 ms·
What's in these files? models/ CartModel.js ProductModel.js SearchResultsModel.js UserModel.js I have a lot of controllers, directives, filt
by Kiro 14y ago
What's in these files?
models/
CartModel.js
ProductModel.js
SearchResultsModel.js
UserModel.js
I have a lot of controllers, directives, filters and services which sit fine in their own files/modules but I don't understand what I would put in a model file.
- olouv 14y agoModel files in angularJS are often basic wrappers around either $ressource or $http. From that you can add default values, collection-like functions, etc.
- joshuacc 14y agoDo you happen to have a link to an example for those of us just getting started in Angular?
- psgibbs 14y agoI think typically people start them out in 'services.js' since effectively models in angular are constructors that are created, and then injected whenever you need a certain type (so you have a service that returns the constructor function). A good example of this is how the tutorial treats the restful 'Phone' resource, creating a service that injects the resource where necessary. I've started calling them 'models' rather than 'services' internally as well, so it's interesting to me that others are too. http://docs.angularjs.org/tutorial/step_11 http://docs.angularjs.org/tutorial/step_11
- joelhooks 14y agoThe Model files are storing state, essentially. In this case they are following a pattern from Robotlegs (as3). I wrote it up here http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs-as3-part-2-models/ http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs... These are then injected as "services" in your controllers.