What is MVVM
The MVVM pattern is the abbreviation for the Model-view-viewmode pattern.
Consists of a view, a view model (ViewModel), a model, and three parts that implement UI logic, rendering logic and state control, and separation of data from business logic.
Responsibilities at each level
Model is used to encapsulate data related to the business logic of the application and how to handle the data. It has the right to direct data access, such as access to the database, model does not depend on ViewModel, that is, the model does not care how it will be displayed or how it is manipulated, and does not contain any user interface-related logic.
The view layer relies on the ViewModel layer to display the data according to the defined structure and build the page.
ViewModel is the model layer and the view layer of the bridge, that is, the so-called protocol, with the agreement, the model layer and the view layer can do each of the things, without worrying about unnecessary changes.
Is the access between the layers of the MVVM pattern:
The advantages of MVVM
1. Low coupling .
Views can be independent of model changes and modifications, a viewmodel can be bound to different "view", when the view changes the model can be unchanged, when the model changes when the view can be unchanged.
2. Independent development .
Developers can focus on business logic and Data Development (ViewModel), and designers can focus on page design.
3. Can be tested .
The interface is always more difficult to test, and now the test can be written for ViewModel.
How Angularjs is implemented in MVVM
A controller is a combination device that obtains data through the service (Model) and then binds to the ViewModel of the controller's $scope object and then to the view page through a two-way binding of the data.
Angularjs Learning Note (ii) MVVM