What is AngularJS Modules?

Modules in AngularJS define an application. These are used to divide the logic such as controllers, services, application etc. and keep the code clean. It is define in separate js file. Controllers always belong to a module.

Example

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">
{{ first + " " + second }}
</div>
<script>
var app = angular.module("intellipaatApp", []);  // Application Module
app.controller("intellipaatCtrl", function($scope) {  // Controller Module
$scope.first = "Hello";
$scope.second = "Intellipaat";
});
</script>
</body>
</html>

Output
Hello Intellipaat

Angular vs React Tutorial Video

Modules and Controllers in Files

e.g.

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">// User Module
{{first + " " + second}}
</div>
<script src="intellipaatApp.js"></script>
<script src="intellipaatCtrl.js"></script>
</body>
</html>

Output
Hello Intellipaat
In this example intellipaatApp.js have an application module definition and intellipaatCtrl.js have the controller

Course Schedule

Name Date Details
Web Development Courses 25 Mar 2023(Sat-Sun) Weekend Batch
View Details
Web Development Courses 01 Apr 2023(Sat-Sun) Weekend Batch
View Details
Web Development Courses 08 Apr 2023(Sat-Sun) Weekend Batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *

Find Best AngularJS Training in Other Regions

Bangalore Hyderabad Chennai Mumbai