Create Module in AngularJS

AngularJS allow us to manage all our JavaScript code into modules to avoid declaring objects and variables in the global namespace. We can consider AngularJS module as container-fluid for the services, controllers, application etc.

A Controller always belong to a module.


A AngularJS module can be defined by calling the angular.module function like below.

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


<!DOCTYPE html>
<script src="//"></script>
<body ng-app="firstModule" >
<div ng-controller="simpleController">
<strong>First name:</strong> {{firstName}}<br />
<strong>Last name:</strong> {{lastName}}</span><br />
<strong>Full name:</strong> {{getFullName()}}<br />
<label>Set First name: <input type="text" ng-model="firstName"/></label><br />
<label>Set Last name: <input type="text" ng-model="lastName"/></label>
angular.module("firstModule", [])
var simpleController = function ($scope)
  // Initialize the model variables
  $scope.firstName = "Max";
  $scope.lastName = "Joe";
  // Define utility functions
  $scope.getFullName = function ()
return $scope.firstName + " " + $scope.lastName;