AngularJS does not have a model: it's not MV*, but rather VM*

gwagner's picture

Where is the "model" in AngularJS? The answer to this question is:

AngularJS does not work with a real model but just with a view model. Therefore, it shouldn't be called an MVC framework, and neither an MVW nor an MV* framework, but rather a View-Model-Whatever (or VM*) framework.

A real MV* framework is based on model classes, like BackboneJS or ASP.NET MVC. A model class does not only define properties and methods for the objects that instantiate it. It also defines property constraints that are checked when validating user input. These constraints are defined in the model, but they are not only checked in the model (before save), but also in the view (on field input, on field change and on form submit).

AngularJS does not have any concept of model class. It requires to define the validation logic in the view instead of the model. AngularJS binds HTML form fields and other HTML elements to special variables defined as properties of a view controller's $scope object. These variables represent view model fields, rather than properties of a model class.

The fact that AngularJS supports reading and saving the values of its $scope variables from/to a remote data store doesn't turn these view fields into model properties. It just means that the AngularJS approach implies forwarding the field values directly to a cloud storage service or to the model of a back-end application without using the logic of a real model (class). The problem with this approach is not only a lack of model logic for constraint validation, but also a lack of model logic for associations and for inheritance relationships between model classes.

So, clearly, in an AngularJS app, there is only a view model and a view, but no model!