angular-jsonapi icon indicating copy to clipboard operation
angular-jsonapi copied to clipboard

How to deserialize

Open nicooga opened this issue 9 years ago • 0 comments

I need a way to tell the resource API to deserialize server sent dates as strings ("2016-05-13") into javascript dates so angular-material datepicker doesn't wine about model being an string.

I can't seem to find a way to do this without getting deep into the source of the package. Do you know a simple way to do this?

Currently I'm doing this to override resource's initialize function:

// ....
function factoryConstructor($jsonapi) {
  var resource = $jsonapi.getResource("expenditure");

  resource.initialize = function() {
    var res = this.__proto__.initialize.apply(this);
    res.form.data.attributes["expent-at"] = new Date();
    return res;
  }

  return resource;
}

I would be cool if I could override another function like deserialize(jsonObj) to make this work.

nicooga avatar May 15 '16 02:05 nicooga