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

AngularJS Modules

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

If you want to learn about AngularJS Expressions, refer to our Angular blog!

Course Schedule

Name Date
Web Development Courses 2021-09-18 2021-09-19
(Sat-Sun) Weekend batch
View Details
Web Development Courses 2021-09-25 2021-09-26
(Sat-Sun) Weekend batch
View Details
Web Development Courses 2021-10-02 2021-10-03
(Sat-Sun) Weekend batch
View Details

Leave a Reply

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