Home  >  Article  >  Web Front-end  >  What is the relationship between model, Controller and View in AngularJs? (pictures and text)

What is the relationship between model, Controller and View in AngularJs? (pictures and text)

不言
不言Original
2018-07-21 17:26:542392browse

The use of AngularJs to build applications is inseparable from (Model), controller (Controller), view (View) and ViewModel, so what is the specific relationship between them? Today I will give you a brief analysis of the relationship between them.

1. Model: It is an encapsulation carrier of data related to the business logic of the application. It is an object in the business field. The Model does not care how it will be displayed or operated, so the model will not contain any The interface displays relevant logic. In web pages, most models are data returned from the Ajax server or global configuration objects, while services in angular are the place to encapsulate and process business logic related to the Model. Such business services can Domain services reused by multiple Controllers or other services.

2. Controller: This is not the core element of the MVVM pattern, but it is responsible for the initialization of the ViewModel object. It will combine one or more services to obtain the business domain Model and place it on the ViewModel object, making the application interface The available state is reached during startup loading.

3. ViewModel: The $scope object in angular fully plays the role of the ViewModel. It is the glue of the View and the Model, which conforms to the interaction and collaboration between the View and the Model. It is responsible for providing display information to the View. Data, and provides a way to operate the Model through events in the View.

4. View: It focuses on the display and rendering of the interface. In angular, it contains a bunch of declarative Directive view templates.

The following is a diagram to represent the relationship between model, controller, view and ViewModel:

What is the relationship between model, Controller and View in AngularJs? (pictures and text)

Related recommendations:

Solution to conflicts between template views and AngularJS

Communication between AngularJS controllers Detailed explanation of the method

The above is the detailed content of What is the relationship between model, Controller and View in AngularJs? (pictures and text). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn