Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 11, 2012 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/4256498 to your computer and use it in GitHub Desktop.
Save jrmoran/4256498 to your computer and use it in GitHub Desktop.
AngularJS intercept responses - array of strings to array of objects
app.config( function( $httpProvider ) {
var interceptor = function( $q ) {
return function( promise ) {
var success = function(res) {
if(res.data && res.data[0]){
if(typeof res.data[0] === 'string'){
var data = res.data,
ret = [];
angular.forEach(data, function(d){
ret.push({data: d});
});
res.data = ret;
return res;
}
}
};
var error = function(res) { };
promise.then( success, error );
return promise;
}
};
$httpProvider.responseInterceptors.push( interceptor );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment