Example of module dependencies
In this blog we'll describe how to use multiple module in single controller and how to use provider in Angularjs .for more understanding see given image below.
Step 1:-Create HTML page using angularjs.js library or CDN:-
<strong>provider1 ID:</strong> <br/>
<strong>provider2 ID:</strong> <br/>
<strong>provider3 ID:</strong> <br/>
Step 2:-Create script.js file
//Definition of a BaseProvider item to utilize
//in various occasions crosswise over various modules.
var BaseProvider = capacity ()
setID: capacity (id)
providerID = id;
$get: capacity ()
getProviderID: capacity ()
angular.module("childModule1", [ ]).provider("provider1", BaseProvider)
}).provider("provider2", BaseProvider).config(function (provider2Provider)
.provider("provider1", BaseProvider).config(function (provider1Provider)
}).provider("provider3", BaseProvider).config(function (provider3Provider)
angular.module("childModule3", [ ]).provider("provider1", BaseProvider)
}).provider("provider4", BaseProvider).config(function (provider4Provider)
//"mainModule" relies on upon "childModule1" and "childModule2". The "provider1" //example
//in "childModule2" overrides the "provider1" example characterized in //"childModule1"
//in light of the fact that both the modules are conditions of "mainModule" and in the //conditions
//exhibit "childModule2" comes after "childModule1". In the event that the conditions cluster was
//["childModule2", "childModule1"] then "provider1" in "childModule1" would //override
//"provider1" in "childModule2". "provider1" in "childModule3" is overridden by the
//same definition in alternate modules on the grounds that alternate modules are //closer to
//the foundation of the pecking order (they are offspring of "mainModule", while //"childModule3"
//is an offspring of "childModule2").
//I can get every one of the suppliers in alternate modules through Dependency //Injection
//on the grounds that there's just a level (with no order) gathering of supplier names
//in the entire AngularJS application and it doesn't rely on upon the modules chain of //importance.
.controller("mainController", capacity ($scope, provider1, provider2, provider3, provider4)
//Set variables on the degree to reference the diverse suppliers from the HTML layout
$scope.provider1 = provider1;
$scope.provider2 = provider2;
$scope.provider3 = provider3;
$scope.provider4 = provider4;
angular.module("mainModule", ["childModule1", "childModule2"])
In AngularJS, we call benefit any item enrolled in a module through the accompanying capacities: esteem, administration, production line, supplier.
A module can rely on upon different modules in this way framing a chain of importance, however benefits characterized into modules don't shape a progressive system and when the application is stacked they all go into a one of a kind namespace. An administration is obvious (and accessible for Dependency Injection) to every one of the modules stacked in the same application freely of the modules progressive system.
An administration name can be utilized to enlist just a solitary administration in the entire application.
mainModule relies on upon childModule1 and childModule2 while childModule2 depends just on childModule3.
For every module we can see the names of the enrolled administrations and the same name provider1 is utilized by all the tyke modules to enlist diverse administrations.
The provider1 occasion in childModule2 overrides the provider1 occurrence characterized in childModule1 in light of the fact that both the modules are conditions of mainModule and in the conditions exhibit childModule2 comes after childModule1. In the event that the conditions cluster was [childModule2, childModule1] then provider1 in childModule1 would override provider1 in childModule2. provider1 in childModule3 is overridden by the same definition in alternate modules on the grounds that alternate modules are closer to the foundation of the order (they are offspring of mainModule, while childModule3 is an offspring of childModule2).
Bikesh Srivastava AngularJs