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.Code Organization in Large AngularJS and JavaScript Applications
11–20 of 24 posts
Re: Code Organization in Large AngularJS and JavaScript Applications
#12I'm not sure I agree with the idea of adding utility methods to the $rootScope to avoid wiring in dependencies repeatedly. I would probably go with defining a utility class and indeed injecting it into every controller that needs it. I like the idea of having my utility methods clearly defined in one place. Any opinions here on the pros/cons?
Re: Code Organization in Large AngularJS and JavaScript Applications
#13I was surprised at Angular-seed's directory structure. It is fine for toy apps, but that isn't what it is really being billed as. I'm building a django/angular app. Each django app gets its own angular module, and each angular module roughly shares the seed structure, but may be broken into more files (much like the second example in TFA). So my whole structure looks something like: django-project/ app1/ views.py sta…
My one tip: forget about using Django to manage your assets if you need cache-busting... use fabric and something like grunt.
Re: Code Organization in Large AngularJS and JavaScript Applications
#14Re: Code Organization in Large AngularJS and JavaScript Applications
#15I'm not sure I agree with the idea of adding utility methods to the $rootScope to avoid wiring in dependencies repeatedly. I would probably go with defining a utility class and indeed injecting it into every controller that needs it. I like the idea of having my utility methods clearly defined in one place. Any opinions here on the pros/cons?
I'm for using services to define whatever object used across controllers and other services. Using rootscope or scope inheritance is very tricky in AngularJS
Using $rootScope feels like a hack.
Re: Code Organization in Large AngularJS and JavaScript Applications
#16What'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.
Re: Code Organization in Large AngularJS and JavaScript Applications
#17What'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.
Model files in angularJS are often basic wrappers around either $ressource or $http. From that you can add default values, collection-like functions, etc.
Re: Code Organization in Large AngularJS and JavaScript Applications
#18What'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.
These are then injected as "services" in your controllers.
Re: Code Organization in Large AngularJS and JavaScript Applications
#19Earlier quoted context omitted.
Model files in angularJS are often basic wrappers around either $ressource or $http. From that you can add default values, collection-like functions, etc.
Do you happen to have a link to an example for those of us just getting started in Angular?
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.
Re: Code Organization in Large AngularJS and JavaScript Applications
#20My applications are backbone based and my directory structure is similar to :
scripts/
classes/
collections/
socket.coffee
ui/
popup.coffee
page.coffee
models/
user.coffee
collections/
items.coffee
products.coffee
ui/
navigation/
top.coffee
sidebar.coffee
overlay.coffee
pages/
landing/
home.coffee
about.coffee
cms/
home.coffee
admin.coffee
utils/
templates.coffee
landing.coffee
cms.coffe
What's important in my app is classes path. I put there only reusable classes, and using coffeescript I can simply extend the whole module by class Items extend require('classes/collections/socket.coffee')
module.exports = new Items()
Also I always use utils folder, for general javascript helper functions.