Understanding Controllers in AngularJS

Tutorials Shared by the Internet Community

Advertisements


Synopsis

AngularJS is built upon Model View Controller Architecture. So whatever you specify in the html elements using directives will have a controller.

Statistics

  • Total Hits - 26565

  • Total Votes - 247 votes

  • Vote Up - 148 votes

  • Vote Down - 99 votes

  • Domain - www.programming-free.com

  • Category - Web Design/Framworks

  • Submitted By - PRIYADARSHINI

  • Submitted on - 2013-10-14 02:30:55

Description

This article is a continuation of the series of articles written on AngularJS. In the previous post, we saw what is AngularJS and with a basic understanding of AngularJS Directives, let us now proceed to learn Controllers in AngularJs. AngularJS is built upon Model View Controller Architecture. So whatever you specify in the html elements using directives will have a controller at the backend that binds model with the view.

Controllers are Javascript functions that contains the business logic and binds view to model. There is one more thing you should know at this point of time and it is about the 'Scope' object. Scope ($scope) is nothing but a javascript object that glues your view with model data. They hold the model data that is to be presented to the view. If you take a look at the above image, it is clear that the controller 'FooCtrl' is binded to the HTML element using 'ng-controller' directive and '$scope' object hold the data to be provided to this html element. Let us now try to understand this better with a practical example. ...


Site  |   Broken  |   Tweet  |   Facebook  |     |   Save  |   Liked  |   Down

Advertisements