$scope.observer_vel_data = function(){
$scope.showOverlay('loadRefPubVel');
$http({
//Making the first http post request
method:'POST',
url:'/api/observer_vel_data',
data:$scope.payload_array,
}).then(function successCallback(response){
console.log('Successfully fetched velocity data from API endpoint!');
//Making the second post request to fetch sentiment data
$scope.sentiment_var = $scope.observer_send_sentiment();
$scope.vel_var = response.data.velocity1;
}, function errorCallback(response){
// Handle API call failure
$scope.addAlert({
type: 'danger',
msg: 'Failed to fetch data from API'
});
}).finally(function(){
console.log("hello");
console.log($scope.sentiment_var);
//Render the graph with fetched data
$scope.update_velocity($scope.vel_var,$scope.sentiment_var);
$scope.hideOverlay('loadRefPubVel');
});
};
Trying to render a graph using data from two separate post requests, but facing timing issue with the second request data. Need help to resolve this. Details of the post requests and graph rendering commands are mentioned in the code.
$scope.observer_send_sentiment = function (){
// $scope.showOverlay('loadRefSentiment');
var data = {
"angularGroups":$scope.groups
};
// console.log(data);
$http({
method:'POST',
url:'http://localhost:9612/sentiment_velocity',
data:data
}).then(function successCallback(response){
var data = response.data;
var json_obj = JSON.parse(data.replace(/\'/g,'"'));
var sentiments = json_obj["sentiments"];
// console.log(sentiments);
$scope.update_sentiment(sentiments);
console.log(sentiments);
return sentiments;
}, function errorCallback(response){
var errmsg = response.statusText;
console.log(response);
$scope.addAlert({
type: 'danger',
msg: 'API call failed (sentiment basic)' + errmsg,
});
}).finally(function(){
// $scope.hideOverlay('loadRefSentiment');
});
};