AngularJS Example:
by witoldsz
HTML
<div ng-app="my-app">
<p>
How is that <tt>'module-A'</tt> can inject <i>otherName</i>
even though it is declared in <tt>'module-other'</tt>,
which was <strong>NOT</strong>
declared as a dependency of <tt>'module-A'</tt>?
</p>
<hr/>
<div ng-controller="ModuleAController">
<p>module A: <strong>{{moduleAName}}</strong></p>
<p>module Other: <strong>{{moduleOtherName}}</strong></p>
</div>
</div>
CSS
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script> <style> .done-true {
text-decoration: line-through;
color: grey;
}
JavaScript
//imagine this is a big application
//with many many modules (just the three for this demo)
angular.module('my-app', ['module-A', 'module-B', 'module-other']);
//many files later:
//where does, On Earth, the "otherName" come from??
angular.module('module-A', ['module-B'])
.controller('ModuleAController', function ($scope, otherName) {
$scope.moduleAName = 'My name is A';
$scope.moduleOtherName = otherName;
});
//few files later:
angular.module('module-B', [])
/* factories, controllers, directives and what-not, but no 'otherName' */;
//many many files later:
angular.module('module-other', [])
.constant('otherName', 'My name is Other');