1

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Elad Israeli
  • 131
  • 2
  • 11
  • Is Angular that much different than Knockout? Because, in Knockoutjs, you define a javascript object that's your ViewModel, which has observable properties and collections, and you apply it to your UI via the javascript command `ko.applyBindings(myViewModel);` Maybe knockout is better suited to your understanding of the pattern? –  Dec 07 '15 at 18:39

1 Answers1

0

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;
           });
       }]);
R. Salisbury
  • 1,954
  • 16
  • 17
  • another question that come with this answer is can i using variables in this section i mean factory , services, providers etc... and does this vars are singletone i mean if i change the info it will stay till the application still alive? – Elad Israeli Dec 07 '15 at 21:16
  • You can make them whatever you want. In fact, under the hood there is no real difference between a factory and a service. It's just a dependency-injected object. – R. Salisbury Dec 08 '15 at 22:04