What I would recommend in this case would be to use 2 separate functions. One for each $http
that you need to do. This will give you more freedom, including in reusing the code.
Getting kind of like this:
function http1() {
return $http.get('seu/caminho/arquivo.json').then(
function (response) {
outroHttp(response);
},
function (err) { alert('Alerta de erro'); }
);
};
function outroHttp(data) {
return $http.post('seu/caminho/arquivo.php', data).then(
function (response) {
//Seu tratamento de dados aqui
},
function (err) { alert('Alerta de erro'); }
);
};
In this way, you can call the function both through a function coming from the DOM:
<div ng-click="chamaHttp1()">Chama Função 01</div>
and in the controller:
$scope.chamaHttp1 = http1();
Or reuse within the controller itself, following the same logic used in the function http1()
.
Thanks! I got it working!
– Marcos Muller