Skip to content

Instantly share code, notes, and snippets.

@pitakill
Created December 12, 2016 17:43
Show Gist options
  • Save pitakill/09dffeaab8c76ddfc93120ca0daa1eba to your computer and use it in GitHub Desktop.
Save pitakill/09dffeaab8c76ddfc93120ca0daa1eba to your computer and use it in GitHub Desktop.
/*
* redsep backoffice
* */
angular.module('redsep')
.factory('SharedData', ['$http', '$q', function($http, $q) {
var info = {};
return $http.get('/api/v1/me').then(function(responseMe){
info.user = responseMe.data;
if(info.user.channel){
$http.get('/api/v1/channels/' + info.user.channel.id ).then(function(responseChannel){
info.channel = responseChannel.data;
return info;
});
}
return info;
});
}]);
// Rewrite of the snippet above
angular
.module('redsep')
.factory('ShareData', [$http, $q, fuction($http, $q) {
var info = {};
var me = $http.get('/api/v1/me')
var channels = $http.get('/api/v1/channels/' + info.user.channel.id )
var promises = {
me: me,
channels: channels
};
$q
.all(promises)
.then(function(responses){
info.user = responses.me.data;
info.user.channel = responses.channels.data;
return info;
})
.catch(function(errors){
console.log(errors);
})
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment