Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm currently trying this pattern, which, although not DCI, provides a classical service / model decoupling (with services for talking to web services (aka model CRUD), and model defining the object properties and methods). </p> <p>Note that i only use this pattern whenever the model object needs methods working <strong>on its own</strong> properties, that i'll probably use everywhere (such as improved getter/setters). I'm <strong>not</strong> advocating doing this for every service systematically. </p> <p><strong>EDIT: I used to think this pattern would go against the "Angular model is plain old javascript object" mantra, but it seems to me now that this pattern is perfectly fine.</strong></p> <p><strong>EDIT (2): To be even clearer, I use a Model class only to factor simple getters / setters (e.g. : to be used in view templates). For big business logic, i recommend using separate service(s) that "know" about the model, but are kept separated from them, and only include business logic. Call it a "business expert" service layer if you want</strong></p> <p><strong>service/ElementServices.js</strong> (notice how Element is injected in the declaration)</p> <pre><code>MyApp.service('ElementServices', function($http, $q, Element) { this.getById = function(id) { return $http.get('/element/' + id).then( function(response) { //this is where the Element model is used return new Element(response.data); }, function(response) { return $q.reject(response.data.error); } ); }; ... other CRUD methods } </code></pre> <p><strong>model/Element.js</strong> (using angularjs Factory, made for object creation)</p> <pre><code>MyApp.factory('Element', function() { var Element = function(data) { //set defaults properties and functions angular.extend(this, { id:null, collection1:[], collection2:[], status:'NEW', //... other properties //dummy isNew function that would work on two properties to harden code isNew:function(){ return (this.status=='NEW' || this.id == null); } }); angular.extend(this, data); }; return Element; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload