Reputation: 4915
The service is returning data
(the raw $http response) rather than result
(the processed version I want to pass back to my controller), why is the code inside promise
being ignored?
///in controller
Romanize.get($scope.currentMaterial).then(function(d){
$scope.romanized = d;
});
//service
app.factory('Romanize', ['$http', 'Position', function($http, Position){
return{
get: function(query){
var url= Position.sections[Position.sectionNumber].romanizeService + "?korean=" + query;
var promise = $http.get(url).success(function(data) {
var parts = $(data).find("span");
var array = [];
for (var x = 0; x<parts.length; x++){
array.push(parts[x].title);
}
var result = array.join("");
return result;
});
return promise;
}
};
}]);
Upvotes: 2
Views: 81
Reputation: 23394
success
handler does not provide chain. You should use then
:
var promise = $http.get(url).then(function(data) {
var parts = $(data).find("span");
// ...
return result;
});
Upvotes: 2