MOCKSTACKS
EN
Questions And Answers

More Tutorials









Angular Modules declaration


Module is a container for various parts of your applications - controller, services, filters, directive, etc.

Why to use Modules

Most applications have a main method that instantiates and wires together the different parts of the application. Angular apps don't have main method.

But in AngularJS the declarative process is easy to understand and one can package code as reusable modules. Modules can be loaded in any order because modules delay execution.

declare a module

var app = angular.module('myApp', []);
// Empty array is list of modules myApp is depends on.
// if there are any required dependancies,
// then you can add in module, Like ['ngAnimate']
app.controller('myController', function() {
 // write your business logic here
});


Module Loading and Dependencies
1. Configuration Blocks: get executed during provider and configuration phase.

angular.module('myModule', []).
config(function(injectables) {
 // here you can only inject providers in to config blocks.
});


2. Run Blocks: get executed after the injector is created and are used to start the application.

angular.module('myModule', []).
run(function(injectables) {
 // here you can only inject instances in to config blocks.
});



Conclusion

In this page (written and validated by ) you learned about AngularJS Modules declaration . What's Next? If you are interested in completing AngularJS tutorial, your next topic will be learning about: AngularJS Components.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.