This article mainly introduces the modules in AngularJS. This article describes examples of its application modules and controller modules. For more information, see how AngularJS supports modularity. The module is used to logically represent services, controllers, applications, and so on, and keep the code clean and tidy. We define a module in a separate js file and name it in the form of a module. js file. In this example, we will create two modules.
- Application Module-used to initialize the controller Application
- Controller Module-used to define the Controller
Application Module
mainApp.jsvar mainApp = angular.module("mainApp", []);
Here, we have declared the application mainApp module using the angular. module function. We have passed an empty array to it. This array usually contains subordinate modules.
Controller Module
StudentController. js
mainApp.controller("studentController", function($scope) { $scope.student = { firstName: "Mahesh", lastName: "Parashar", fees:500, subjects:[ {name:'Physics',marks:70}, {name:'Chemistry',marks:80}, {name:'Math',marks:65}, {name:'English',marks:75}, {name:'Hindi',marks:67} ], fullName: function() { var studentObject; studentObject = $scope.student; return studentObject.firstName + " " + studentObject.lastName; } };});
Here, we have declared that the controller uses the mainApp. controller function of the studentController module.
Modules
..