javascript - Do things in $http.then(), and then return promise -


inituserprofile: function() {    return $http.get('myapi/user/profil').   then(function(response) {     current_user = response.data;     if (current_user.profilpicture) {       current_user.profilpicture = $rootscope.baseurl + "/images/users/" + current_user.username + "/" + current_user.profilpicture;     }   }, function(err) {     // log error   }); }; 

i want return promise, here it's case it's $http success promise. how can return promise when changes inside then() completed ?

just return current_user in then() , available argument of next then() in chain

inituserprofile: function() {    return $http.get('myapi/user/profil').   then(function(response) {     current_user = response.data;     if (current_user.profilpicture) {       current_user.profilpicture = $rootscope.baseurl + "/images/users/" + current_user.username + "/" + current_user.profilpicture;     }       return current_user;     }).catch(function(err) {     // log error   }); }; 

in controller:

myservice.inituserprofile().then(function(current_user){     $scope.user = current_user; }) 

Comments