Anjular JS Modules and Controllers
Module
is container for different parts of
application, i.e controllers,services,directives,filters,expressions…..
Everything should be register with module. we can say
anjularjs development is moduler programming model which provides more
advantages over the development.
How to create a module ?
var myapp = angular.module("app", []);
here
anjular is object provided by anjularjs
framework to define a module,we defined a module myapp.(name of the module is “app”).
[]
this module is not dependent on any other module so that we placed an empty
array.
How
to create a controller ?
Controller is javascript constructor function.
Which is responsiable for building model object( constructing a model object/data),generally
controller fetch data from service(web api/webservice) to fetch the data in
projects for dynamic data.
var mycontroller
= function ($scope)
{
$scope.message = "Welcome to AnjuarJS";
}
Now we need to
register this function to module as controller.
Approach 1 : As anonymous function
here
$scope is an anjularjs object which is maintain by anjular to maintain/save sate of message object.
here
Controller is a javascript function.
Controller is a javascript function.
$scope is anjular object to save the state of object.
message is object/model with the help of $scope object saving state("welcome to anjularjs") persisting it.
No comments:
Post a Comment