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 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\"


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

Recommended Videos

Leave a Reply

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

Solve : *
48 ⁄ 24 =