Overview
In an earlier article, we saw what AngularJS is, why AngularJS is used, what benefits it provides over other JavaScript frameworks, how to include AngularJS in your page, and its various directives. For more details, kindly refer to this article.
In this article, we will see what modules and controllers are in AngularJS. In this part, we will see.
- What are modules and Controllers in AngularJS?
- How to create a module in AngularJS
- How to create a Controller in AngularJS
- How to register a controller with a Module and then assign that controller to our respective Page.
Introduction
Just kindly create a simple solution called AngularJS. Download Angular JS scripts from the official website. You can also download it from NuGet packages.

Search AngularJS.
Click on Install and it will install the AngularJS in your application.
Now, right-click on the solution and add html or aspx page.
What are modules in AngularJS?
Modules are nothing but containers for different parts of your application, like directives, filters, etc.
Why is a module required?
The module is the main() method in your AngularJS application.
For Example
A console application has a main() method which is the entry point of your application. Similarly, a module in AngularJS is your main entry point of your application.
Modules specify how the angular application will bootstrap.
How to Create a Module in Angular?
We will use the angular object method() to create a module
var mypartone = angular.module("mymodule", []);
You will notice that angular.module(“mumodule”,[]); are having two parameters at the moment.
The first parameter specifies the name of the module and the second parameter specifies the dependencies which are associated with that module.
Note. A module can depend on another module too.
What is a Controller in AngularJS?
In AngularJS, the controller is a JS function. The main part of the controller is to build a model for viewing, to display various details on the page. Here, the model is nothing but data. A controller may call a web Server which retrieves data from a database.
How to Create a Controller in AngularJS?
var myController = function($scope) {
$scope.message = "Hello C-SharpCorner Team";
};
Note. We are creating an anonymous function here, which is a function($scope) and we are assigning it to a variable here. Here, we are passing a parameter called $scope.
What is $Scope?
$Scope is nothing but an angular object that is passed to the controller function by the angular framework, automatically. We attached the model to this $scope object which will be then available in the respective views.
Now, in the view, we are using a data-binding expression to display details. Here, we are passing message property to this $scope object and it's storing a string.
$scope.message = "Hello C-SharpCorner Team";
And displaying Hello C-sharp corner Team.
Code Part
Let's go to the Visual Studio.
Now, we add a simple JavaScript file, first, in our Script Folder.













Akshay PhadkePosted Jul 16, 2016, 1:21 PM
Thankyou :)
Shobana JPosted Jul 16, 2016, 6:30 AM
Good one
Debasis SahaPosted Jul 16, 2016, 2:20 AM
Good One..
kalu singh raoPosted Jul 16, 2016, 2:07 AM
Good...