javascript - Where should I put AngularJS Factories & Services? -


i'm working cleanly structure angularjs app according best practices, includes separating controllers , app different script files.

quick question: where should put factories , services? asking in context of having factories & services accessed outside of scope of single controller having within scope of single controller.

update: immediate answer below no longer correct. please see latest addendum (written march 1, 2015) answer.

got it! according brian ford's article on building huuuuuuuge angular apps, best practice appears to connect services , factories app in separate file, so:

root-app-folder ├── index.html ├── scripts │   ├── controllers │   │   └── main.js │   │   └── ... │   ├── directives │   │   └── mydirective.js │   │   └── ... │   ├── filters │   │   └── myfilter.js │   │   └── ... │   ├── services │   │   └── myservice.js │   │   └── ... │   ├── vendor │   │   ├── angular.js │   │   ├── angular.min.js │   │   ├── es5-shim.min.js │   │   └── json3.min.js │   └── app.js ├── styles │   └── ... └── views     ├── main.html     └── ... 

(psst! in case you're wondering, brian ford part of angularjs team, answer seems pretty legit.)

addition (april 24, 2013)

this in: yeoman fantastic tool generating apps proper directory structure big, functional angular apps. has grunt & bower packed in!

addendum (march 1, 2015)

according a comment via paolocargnin, google recommends different structure, detailed this document. structure should this:

sampleapp/         app.css app.js                                top-level configuration, route def’ns app app-controller.js         app-controller_test.js         components/ adminlogin/                                         adminlogin.css                styles used component adminlogin.js              optional file module definition adminlogin-directive.js                          adminlogin-directive_test.js                         private-export-filter/                         private-export-filter.js                         private-export-filter_test.js userlogin/ somefilter.js somefilter_test.js userlogin.js userlogin.css                 userlogin.html                 userlogin-directive.js userlogin-directive_test.js userlogin-service.js userlogin-service_test.js                         index.html subsection1/ subsection1.js subsection1-controller.js                 subsection1-controller_test.js                 subsection1_test.js                                          subsection1-1/                                                 subsection1-1.css                         subsection1-1.html                         subsection1-1.js                         subsection1-1-controller.js subsection1-1-controller_test.js                 subsection1-2/                                 subsection2/ subsection2.css subsection2.html subsection2.js subsection2-controller.js subsection2-controller_test.js         subsection3/                 subsection3-1/                         etc... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -