April 1, 2020

What is AngularJS MVC?

MVC is nothing but the software design pattern for designing and developing a web application. It is considered as the architectural pattern that has existed for a long time in software engineering. Many languages use MVC architecture with little variations in each one of them but conceptually it remains the same.

In angular, we organize things in some different manner as compare to regular javascript. Therefore, Model View Controller architecture is the most popular and latest way of organizing an application.

Get Practical knowledge of Angular JS MVC at Angular Course

AngularJs MVC Architecture & Components

AngularJS MVC divides an application into three parts- Model part, View Part, Controller Part. Let’s see for what purpose each component of MVC serves:

  • MODEL PART

Model part consists of a database (use to store data), application data (application data are variables that are specific to a user. Application and logic (Logic refers to code that is written to perform a certain task).

  • VIEW PART

View part is the user interface part of an application. The information that is being displayed to the user in an application is written in this part.

  • CONTROLLER PART

The interaction between the model part and view part is controlled by a controller. It is more like software code.

How MVC Works in AngularJS?

We can implement MVC pattern through JavaScript and HTML. HTML helps to implement model part, while JavaScript is for model and controller part.

When a user enters a URL in the browser, according to that specific URL control goes to the server and calls the controller. After that controller uses the appropriate model and appropriate view so that appropriate response can be made for user’s request. It creates the response and that response is sent back to the user.

ii. View Part In Angular Application

It is the presentation part of an application. Through the view part, a user can see the Model part. Therefore, the model and view part join together.

iii. Controller Part In Angular Application

It is the central part of the angular application. Everything starts with a controller in angular. The model part and the view part join with each other. It means whatever happen to the model part automatically effects to the view part and whatever happens to the view part automatically effects to the model part also. Controller joins the model and view part.

Look at this final code with a model part, view part and controller part in the single code.

  1. <!doctype html>
  2. <html ng-app>
  3. <head>
  4. <title>Angular MVC </title>
  5. <script src=”lib/Angular/angular.min.js”></script>
  6. </head>
  7. <body>
  8. <div ng-controller = “address”>
  9. <h1>{ {Person.Name} }</h1>
  10. </div>
  11. <script type=”text/javascript”>
  12. function address($scope){
  13. $scope.Person= {
  14. 'Name' : 'Ram Kumar ',
  15. 'Address' : 'AB Road, Katni',
  16. }
  17. }
  18. </script>
  19. </body>
  20. </html>

Get practical working of this code at Angular Training

This is how MVC Architecture works in angular. The various aspects of an application divided into three components (Model, View and Controller) to separate responsibilities. A model contains application data, a view contains the visual layout and a controller connects the view part and model part. Furthermore, if you have any query, feel free to ask in the comment box.