Reputation: 251
In Angularjs we can create the two modules in our application. Some thing like this.
var myApp = angular.module('myApp', []);
var myApp2 = angular.module('myApp2', ['myApp']);
Why we need to create the two module in the application? Can't we write every thing in one module? Is two modules are use for only the code clarity and easy to understand? Any other purposes?
Upvotes: 1
Views: 57
Reputation: 4974
Usually only one main module will control your application (the one you specify in ng-app, the same one as you specify dependencies on, in your example that's myApp2
). Although it is possible to have 2 modules control your application, this is rare and something I've never seen before.
The other modules you add could either be:
You can create your own modules to group related blocks of code together, or for example when you're writing a library for say, dealing with arrays. In the latter example you could take that module and reuse this for future projects, just by copying it in your project directory and adding it as a dependency on your main module.
Upvotes: 1