A module defines an application. It is container for the different parts of your application like controller, services, filters, directives etc.
Controller always belong to a module.
Creation of a module
A module is created by using the AngularJS function angular.module
The “myApp” parameters refers to an HTML element in which the application will run. Now we can add controllers, directives, filters, and more, to your AngularJS application.
In the following example we will explain module and controller.
- ng-app directive is used to denote that this application should be considered as an angular application. “myApp” is the name given to our AngularJS application.
- In body tag we have added an ng-controller directive along with the name of our controller “myControl”. This basically makes our body tag the ability to access the contents of the “myControl”. We need to mention the name of the controller under the directive to ensure that we are able to access the functionality defined within the controller.
- We are creating a module which will attached to our “myApp” So this module now becomes part of our application.
- In the module, we define a function which assigns a value of “Bit” and “Byte” to our firstName and lastName variables respectively.