Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications. A Model View Controller pattern is made up of the following three parts −
MVC is popular because it isolates the application logic from the user interface layer and supports separation of concerns. The controller receives all requests for the application and then works with the model to prepare any data needed by the view. The view then uses the data prepared by the controller to generate a final presentable response. The MVC abstraction can be graphically represented as follows.
The model is responsible for managing application data. It responds to the request from view and to the instructions from controller to update itself.
A presentation of data in a particular format, triggered by the controller’s decision to present the data. They are script-based template systems such as JSP, ASP, PHP and very easy to integrate with AJAX technology.
The controller responds to user input and performs interactions on the data model objects. The controller receives input, validates it, and then performs business operations that modify the state of the data model.
AngularJS is a MVC based framework.
One of the most critical concepts to understand when learning AngularJS is the separation of state from the DOM. AngularJS is officially a Model-View-Whatever (MVW) framework—“Whatever” being whatever pattern helps you be most productive. For the sake of conversation, let’s assume that AngularJS follows the Model-View-ViewModel (MVVM) design pattern, as established in following Figure
The View in the MVVM pattern is the view in AngularJS (naturally), and the controller plays the part of the ViewModel.
The controller is responsible for providing state for the view to bind to and commands that the view can issue back to the controller to do units of work. This frees up the view from having to maintain state (since it only has to display whatever state the controller is in) and it frees up the view from having to do any work (as the view always defers to the controller).