You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
varapp=angular.module('yourModule',[/* your regular deps */]);// flush all registered modules:require('an').flush(app);
Demo
// controller.jsmodule.exports=require('an').controller('AppCtrl',function($scope){$scope.message='Hello World';});// app.jsrequire('./controller.js');// just make sure the controller is registeredvarapp=angular.module('myApp',[]);// flush controller into app:require('an').flush(app);// this is equivalent to:// app.controller('AppCtrl', function() {...});
When you ready to bootstrap application, collect all directives and register them in your main application module:
require('an').flush();
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.