AngularJS Tutorial - AngularJS Modules

In Angular, a module is the main way to define an AngularJS app.

The module contains all of our application code.

An app can contain several modules and each module contains code for one specific functionality.

We can declare a module using the angular.module() method.

When declaring a module, we need to pass two parameters to the method.

  • The first is the name of the module.
  • The second is the list of dependencies(injectables).

In the following code we use setter to define our module.

angular.module('myApp', []);

We can get module by using the same method with only one parameter.

angular.module('myApp')// fetches myApp

Module Properties

Angular modules have properties that we can use to inspect the module.

  • name (string) The name property on the modules gives us the name of the module as a string.
  • requires (array of strings) The requires property contains a list of modules (as strings) that the injector loads before the module itself is loaded.