Posts

Showing posts from February, 2016

Solving quadruple dependency injection problem in Angular

Angular comes with built-in dependency injection and module management system, but it can get a bit tedious to use when your project grows. Especially if you use RequireJS alongside it (a must for almost any project) and also want to be minification-safe with all those dependency injections. Let's look at a simple example with one module that provides a value and another module that prints that value: // answer.js define(["angular"], function(angular) { angular.module("the.answer") .value("TheAnswer", 42); }); // main.js define(["angular", "the.answer" ], function(angular) { angular.module("main", [ "the.answer" ]) .run([ "TheAnswer" , function( TheAnswer ) { console.log(TheAnswer); }]); }); As you can see, to provide a single dependency to my code, I had to specify it in four places (highlighted in red) - first as RequireJS dependency, then as Angular module dependency,...