Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Last active February 7, 2016 03:09
Show Gist options
  • Save daniellizik/f3fe181efd736ab9f3be to your computer and use it in GitHub Desktop.
Save daniellizik/f3fe181efd736ab9f3be to your computer and use it in GitHub Desktop.
angular naming styles

#structure

/global
/components

global holds components shared by other components, components are privately scoped components.

#structure per component

/foobar
  foobar.module.js
  foobar.factory.js
  foobar.controller.js
  foobar.component.js
  foobar.config.js
  foobar.run.js
  etc...

#naming inside angular's DI

The factory will always be named app.foobar.api within angular's DI (i.e., it's the name of the internal singleton). The app prefix helps distinguish between project and vendor components.

When the singleton is injected, just name it api. It makes the controllers consistent and encourages each controller to have its own private api.

 angular
   .module('app.foobar', [])
   .factory('app.foobar.factory', require('./foobar.factory')
   .controller('app.foobar.controller', require('./foobar.controller');

 ['app.foobar.factory', function(api) {
    this.api = api;
 }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment