1
I need to use a variable, at the angle, that I can use in more than one controller. Yes controllers are in the same file. How can I do that?
.controller('denResCtrl', function($scope, $window, $http) {
$scope.fazerDenuncia = function (denuncia) {
var diaDenun = formatarData(denuncia.dataDenun);
var hora = denuncia.horaDenun;
var tipo = denuncia.tipoDenun;
var des = denuncia.descricao;
var end = $window.localStorage.getItem('logradouro');
var numeroEnd = denuncia.numeroEndereco;
var cid = $window.localStorage.getItem('cidade');
var estado = $window.localStorage.getItem('estado');
$http.get('http://localhost:8888/sistemas/webApps/ionic/vcApp/www/php/getCordenates.php?end='+end+'&numeroEnd='+numeroEnd+'&cid='+cid+'&estado='+estado).success(function (data) {
var coordenadas = data;
})
}
})
The variables that are in the current controller, I created on it, and did not exist.
Bá! $rootScope is very bearded by what I see. E Marco, what Geferson put in the app.js file a . run and such, would serve if I want to declare a global variable for the whole project, is that it? Or the way you did, also serves?
– GustavoSevero
It also does. It is available throughout your project, but only after this variable is set. However, using it in the run() method or as mentioned by Geferson, the variable is defined at the time the application is initialized.
– Marcos Kubis
Okay, Marcos, I get it. Returning your answer, then, all the variables I created, in this controller, I have to take the var and put $rootScope.variableCreated, right?
– GustavoSevero
If you want them to be available in another controller, yes, that’s right!
– Marcos Kubis
In addition, just don’t forget to inject the $rootScope dependency into the controller, otherwise I bet it will give rsrsrs error
– Geferson