Saturday 15 November 2014

Angular JS - Modules



Controller

The data and logic needed for a particular view is defined inside a controller.The variables and functions are defined in the scope of controller which can be accessed by the view.We can define nested controllers also.Controllers should not contain business logic.Controllers should not hold any data, but only provide references to data in their scopes.

There are 2 ways to create controller mapping,
1.using ng-controller module
2.using router service


Service

Service will handle the data storage and acts as DAO.Controllers can inject the reference to the actual service or mock service in unit testing.

Model

Model Objects are ordinary JavaScript data types and need not be dependant on framework.The models can be bound(i.e) synchronised to the views provided they are defined in the scope of the view.

Routes

Routes map url's with the controller and the template to be rendered.This feature simplifies the forward/backward linking of applications.

$routeProvider is used to define a mapping between a specific template URL and a controller by calling the when() function. The call to the otherwise() function defines a fallback mechanism that applies to all requests that do not match the predefined routes.

No comments:

Post a Comment