From c4d42341b579171959f6a6aec5d9b623fc8a7b1d Mon Sep 17 00:00:00 2001 From: Hassan Date: Wed, 6 Apr 2016 12:07:22 +0430 Subject: [PATCH] Provide 'transformResult' action i use TS files to write my model, it was several days already, that i wanted to append an interface to my model, but it always failed and i was wonder why... asking around, searching a lot... but nothing... Yesterday, i wrote a new module that need to check for input parameter type. i saw what it fails... and again searching through code and topics... so at some point i found angular change my model again... seeing what... i told 'transformResponse' to return an object of type AcDocRow, but after steping through i saw, hey waits, it's again an stringified json :| ... Searching searching searching... -lot of people have same issue, it's not only me... -Angular Resource Pass Object to Http.. and it return the value to angular, angular again modify the object.... -lot of conversion from string to object and vice versa. -no solution... what should i do? well let see through the code... and i add ability to add a new action which modify the actual result. and you can bypass transformResponse too. which seem more complicated. it's all seem to be clean... so i hope it be acceptable by the jury. I also it get updated in new version of angular too... I'm capable of filling the doc, but i'm not a native english talker. so i leave it to your hand. --- 1.4.9/angular-resource.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/1.4.9/angular-resource.js b/1.4.9/angular-resource.js index 8e74b012b7..43a328126a 100644 --- a/1.4.9/angular-resource.js +++ b/1.4.9/angular-resource.js @@ -615,8 +615,13 @@ angular.module('ngResource', ['ng']). 'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object', angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url); } + + var transformedValue = null; // jshint +W018 - if (action.isArray) { + //If user provide transformResult function, returns user needed results + if(action.transformResult){ + transformedValue = action.transformResult(data); + } else if (action.isArray) { value.length = 0; forEach(data, function(item) { if (typeof item === "object") { @@ -636,7 +641,7 @@ angular.module('ngResource', ['ng']). value.$resolved = true; - response.resource = value; + response.resource = (action.transformResult)? transformedValue : value; return response; }, function(response) {