Problem Statement: I have an angular js function that fetches data from a service, I am concatenating some columns and then return the concatenated data.
Angular JS Function:
$scope.findCompanyAddressById = function( cmpId ) {
var address = "";
$http.get(someUrl+'/company/find?id='+cmpId ).
then(function(response) {
$scope.company = response.data;
for( var i=0; i < $scope.company.locations.length; i++ ) {
address += " " + $scope.company.locations[i].street1
address += " " + $scope.company.locations[i].street2
address += " " + $scope.company.locations[i].city
address += " " + $scope.company.locations[i].state
address += " " + $scope.company.locations[i].zip
console.log( "Rendering address: " );
console.log( address ); // logs perfect data.
}
});
return address;
}
returns undefined when function is called something like this:
$scope.concatenatedData = $scope.findCompanyAddressById( 1 );
Any idea on how to return the concatenated data from the above function.