Module of AngularJS is defining an application.
The module and it’s container for the different parts of an application.
The module is a container for the application controllers.
Controllers always belong to a module.
Create Module:
Module is created by using the AngularJS function “angular.module”
"FirstApp" parameter refers to an HTML element in which the application will run.
Can add controllers, directives, filters, and more, into AngularJS application.
Controller Add
Add a controller to your application, and refer to the controller with the ng-controller directive:
Example:
We talk about more about Controller next Session
Add Directive
AngularJS has a set of built-in directives which can use to add functionality to your application.
In addition, you can easily to use the module to add your own directives to your applications:
Example:
Modules and Controllers in Files
It is common in AngularJS applications to put the module and the controllers in JavaScript files.
In this example, "NewApp.js" contains an application module definition, while "Control.js" contains the controller:
Example :
myApp.js
var app = angular.module("NewApp", []);
The [] parameter in the module definition can be used to define dependent modules.
Without the [] parameter, you are not creating a new module, but retrieving an existing one.
Functions can Pollute the Global Namespace
Global functions should be avoided in JavaScript. They can easily be overwritten or destroyed by other scripts.
AngularJS modules reduces this problem, by keeping all functions local to the module.
When to Load the Library
While it is common in HTML applications to place scripts at the end of the <body> element, it is recommended that you load the AngularJS library either in the <head> or at the start of the <body>.
This is because calls to angular.module can only be compiled after the library has been loaded.
Example :
Required fields are marked *
Get all latest content delivered to your email free.