DEV Community

Cover image for What are the controllers in AngularJS?
narendra8989
narendra8989

Posted on

What are the controllers in AngularJS?

To understand the concept of controller, I would suggest you start reading MVC.

MVC is nothing but Model View Controller.

Now every Angular Application is based on MVC structure.

Model : The application which has the business logic and data model, usually the application which is connected with database.

View: The HTML code that will be visible to the user afterwards.

Controller: The code which will call different functions to get the right data from model to the view .

Specifically for an Angular app, every ng-app is assigned a controller. Whenever the said ng-app is started, its controller comes in action. The functionality of the page will then come from this controller.

Controllers in Angular is to expose/bind data to our view via $scope, and to add functions to $scope that contain business logic to enhance view behavior. Presentation logic should remain within views and directives.

Controllers will refresh data every time it gets refreshed on loading, unlike services it retains the data on consequent Refreshes.

Meet the Experts : https://nareshit.com/angularjs-online-training/

Top comments (0)