AngularJS Modules

1.What is the module?

The module can be treated as a container for the different part of your application like controllers, filters , services, directives , etc. The module is an important part of the Angular js dependency injection system.

 

2.How to create a module?

The module is created by the following syntax:

Syntax:

angular.module("myModule",[]);

 

Here, myModule is the name of the module. and [] is where you inject the dependencies.

 

3.How to create a controller in a module?

Add controller to your application.

synatx:

var myFirstModule = angular.module("myFirstModule", []);
myFirstModule.controller("MyController", function);

 

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/
ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myFirstModule " ng-controller="MyController">
{{ firstName + " " + lastName }}
</div>
<script>
var FirstModule = angular.module("myFirstModule ", []);
FirstModule .controller("MyController", function($scope) { $scope.firstName = "Abc"; $scope.lastName = "Learn";
});
</script>
</body>
</html>