fastread homefastrread library fastread menu

AngularJS : Dependencies Between Modules

Tutorial by:Sumit Chauhan      Date: 2016-08-12 00:40:58

❰ Previous Next ❱

As you have seen, values, factories and services are added to an AngularJS module. It is possible for one module to use the values, factories and services of another module. In order to do so, a module needs to declare a dependency on the module which contains the values, factories and services it wants to use. Here is an example:

var myUtilModule = angular.module("myUtilModule", []);

myUtilModule.value  ("myValue"  , "12345");

var myOtherModule = angular.module("myOtherModule", ['myUtilModule']);

myOtherModule.controller("MyController", function($scope, myValue) {


Notice how the second module (myOtherModule) lists the name of the first module (myUtilModule) in the second parameter (inside the array) passed to the angular.module() function. This tells AngularJS that all values, factories and services defined inside the myUtilModule should be available inside the myOtherModule module too. In other words, myOtherModule depends on myUtilModule.

Second, notice how the MyController controller function now declares a parameter named myValue. This value will be provided from the value registered on the myUtilModule module.

❰ Previous Next ❱