Compare MVVM WPF and MVC/MVVM AngularJS

762 Views Asked by At

MVVM Architure in WPF seems to be understandable.

  1. The model in the MVVM pattern encapsulates business logic and data.(It is a specific class who in charge of the business login and data)
  2. The view's responsibility is to define the structure and appearance of what the user sees on the screen. (implements by having a XAML page)
  3. The view model in the MVVM pattern encapsulates the presentation logic and data for the view.(It is a specific class who in charge of the presention login)

Now lets compare it to Angularjs Design pattern MVC/MVVM.

  1. The view is the DOM(html).

  2. The ViewModel is:

the $scope object could be considered the ViewModel that is being decorated by a function that we call a Controller.

And Here Comes The Question

What is the Model in this AngularJS design pattern ?

I understood that maybe the Services should be the model ? can someone make it clear to me?

BTW i want to use ES6 Class to be the model as we talked about in the MVVM WPF Design pattern where the model is a Class.

1

There are 1 best solutions below

2
R. Salisbury On

The models can come from services or factories, e.g.:

angular.module("myModule")
       .factory("urlFactory", function() {
           return {
               myModelSource: 'http://localhost:38324/api/myModel'
           }
       })
       .service("dataSource", ["$http", "urlFactory", function($http, urlFactory) {
           return {
               getMyModel: function() {
                   return $http.get(urlFactory.myModelSource);
               }
           }
       }])
       .controller("myController", ["$scope", "dataSource", function($scope, dataSource) {
           dataSource.getMyModel().then(function(myModel) {
               $scope.viewModel = myModel;
           });
       }]);