In this case, I recommend that you create a factory
, that is, a service. So, whenever you need this data, whether on this or another controller, you can only reference it more easily and modularly.
It would look something like this:
.factory('factCliente', ['$http', function($http) {
//esse aqui faz um get simples
var _getData = function() {
return $http.get("data/index.php");
};
//esse aqui faz o carregamento do dado enviando algum atributo para o php processar
var _getData2 = function(id) {
return $http.post("data/index.php", id);
};
return {
getData: _getData,
getData2: _getData2,
}
}])
And then to call these functions in your controller, you would do so:
.controller("fluxoCtrl", function ($scope, $http, factCliente) {
var mostraTodasContasEntradas = factCliente.getData();
//Ou então
var idCliente = {id: meuId},
mostraTodasContasEntradas = factCliente.getData2(idCliente);
});
So, if you need client data in another control, just inject its factory, ie factCliente
into your new controller, and call the function. Example:
.controller('OutroCtrl', function($scope, factCliente) {
$scope.maisCliente = factCliente.getData();
})
Edit:
The idea is that you do not use your $ http inside the controller, so imagine the following situation:
You have 7 controllers that do the same get from php. If by any chance you change the name of the php, or change the structure of it so that you need to change in your Angular, you will NOT need to change in 7 different places, being propitious for more errors.
The way you did it works, just to PICK up the raw data, let's say it's a simple php select, through the first example (_getData): select * from 'tabela'
, that is, it will get all the data. p>
The second method (_getData2) that I showed it uses POST, because first you send the data and then select the one you need, for example: select from 'tabela' where id = $meuId
.
Have you understood logic?