You are on page 1of 1

What is module in AngularJS

A Module is container for different part of the application i.e controllers, Services,
directives, Filters, etc
Why module is needed
You can think of a module as Main() method in other applications which is entry
point into the application and its responsibility of main method to wire the different
parts of the applications
How to create a module
Use the angular objects module method to create a module
Var myApp = angulr.module(myModule, [ ]);
Here angular object is provided by Angular itself, in this module method it have
two parameters , myModule is the name of the module and other parameter [ ]
is the dependencies of the module.
What is the controller in Angular
In angular Controller is a JavaScript function. The job of the controller is to build a
model for the view to display
In real world application a controller may call web service which retrieve data from
the database
How to create a controller in Angular
Var myController = function($scope){
$scope.message = AngularJS tutorial;
}
Notice here we are passing $scope to the function, it is an angular object pass to
this controller function by automatically, we attach the model to the $scope object
then it will available in the View

Controller in Angular
The job of the controller is to build a model for the view , the controller does this by
attaching model to the $scope, here the $scope is not the model whatever the data
we are attaching to the $scope is the model

You might also like