Angular + npm
Build angular 1.x apps with power of npm modules.
usage
To start using an
just replace angular.{controller|directive|...}('name', fn)
with: module.exports = require('an').{controller|...}('name', fn)
Then in your main file where you bootstrap angular application:
var app = angular;// flush all registered modules:;
Demo
// controller.jsmoduleexports =;// app.js; // just make sure the controller is registeredvar app = angular;// flush controller into app:;// this is equivalent to:// app.controller('AppCtrl', function() {...});
{{message}}
See demo folder for the same code.
Browserified output of the demo folder (browserify ./demo/app.js > ./demo/bundle.js
)
can be found here: https://anvaka.github.io/an/demo
How?
The idea is simple: avoid using angular.module
in npm package, and delay
directives registration up to the point when application is bootstrapped.
E.g. instead of doing:
var myModule = angular
Do:
;
When you ready to bootstrap application, collect all directives and register them in your main application module:
;
Drawbacks
This approach is still not perfect and requires certain discipline to not forget
register your directives via an
. I can also see potential problems with names
collision, versioning (especially when an
itself is updated).
This module is really simple
at the moment, and maybe there is a better way of sharing angular directives on
npm.
Please let me know.
install
With npm do:
npm install an
license
MIT