I'm trying to getting data from one resource within a controller and with the result, I have to do a second http get request.
$http.get('http://' + ProductionConfig.SERVER + '/api/v1/business-config/').then(function (res) {
$scope.selected= res.data;
console.log($scope.selected);
}, function (err) {
console.error('No se ha podido conseguir los datos de empresa ' + err);
});
$http.get('http://' + ProductionConfig.SERVER + '/api/v1/business/id/' + $scope.selected).then(function (res) {
$scope.business= res.data;
console.log($scope.business);
}, function (err) {
console.error('No se ha podido conseguir los datos de empresa ' + err);
});
But when I'm trying to do the second $http.get, $scope.selected is undefined and it retrieves me an error because it has failed with the query . After that, I have to save the result in an object for using it later.
How can I pose this problem? Thanks.
http.get
inside thethen
of the first one – Joao Leal Jun 16 at 10:41