Blog

12 Oct 2018

AngularJS Modules

What are AngularJS Modules?

Basically modules define an application in AngularJS which is also a container for controllers as well as different parts of an application.

 

How can we create a module in AngularJS?

AngularJS has a predefined function “angular.module” which is basically used to create a module in AngularJS.

 

Syntax : 

<div ng-app=”NewModule”>

// Statements …………

</div>

<script>
var app = angular.module (“NewModule”, []);
</script>

 

Let us understand by a simple example.

 

For Example : 

<div ng-app=”NewModule” ng-controller=NewController>
{{ userName  + ” ” + password  }}
</div>

<script>
var app = angular.module(NewModule, []);
app.controller(NewController, function($scope) {
$scope.userName = “angularjs@doc.com”;
$scope.password = “admin”;
});
</script>

 

Output :- angularjs@doc.com admin

Angular JS Training

In Just 4 Days
Enroll Now