AngularJS is based on MVC framework, where MVC stands for Model-View-Controller. MVCperforms the following operations:
- A model is the lowest level of the pattern responsible for maintaining data.
- A controller is responsible for a view that contains the logic to manipulate that data. It is basically a software code which is used for taking control of the interactions between the Model and View.
- A view is the HTML which is responsible for displaying the data.
For example, a $scope can be defined as a model, whereas the functions written in angular controller modifies the $scope and HTML displays the value of scope variable. - In the context of AngularJS, the term “MVC” stands for Model-View-Controller, which is an architectural pattern used to organize and structure the code in a web application. Here’s how MVC is typically implemented in AngularJS:
- Model (M): The Model represents the application’s data and business logic. In AngularJS, models are often created using JavaScript objects or custom services. These models store and manage the data that the application works with.
- View (V): The View is responsible for presenting the data to the user and receiving user input. In AngularJS, the view is typically defined using HTML templates that can include AngularJS directives and expressions to bind data from the model. The view is what the user interacts with.
- Controller (C): The Controller acts as an intermediary between the Model and the View. It handles user input, processes it, and updates the Model and View accordingly. In AngularJS, controllers are implemented as JavaScript functions that are attached to the scope of the view. They manipulate the data in the model and update the view.
AngularJS uses a two-way data binding mechanism, which means that changes in the model automatically update the view, and vice versa. This simplifies the development process by reducing the need for manual DOM manipulation.
It’s important to note that AngularJS is an older framework, and its successor, Angular (commonly referred to as Angular 2+), has introduced significant changes and improvements. Angular (2 and later versions) follows a component-based architecture, which is an evolution of the classic MVC pattern. Components encapsulate the logic for both the view and the controller, promoting better modularity and reusability