Angular does not recognize an out-of-control variable

0

I have a doubt, I have already tried other forums and I did not find the solution. I tested the code below for demonstration purposes only.

*//dentro do controle do angular*
angular.module("NaBalada").controller("NaBaladaLocal", function(data){
    return $scope.teste = 'Testando Angular';
    console.log(testejs)
});
*//Script normal JS*
console.log(teste);*//teste do $scope.teste*
let testejs = 'Variável fora do angular, pra reconhecer dentro do controller'

So, my problem is to get the variables to be seen inside and out, so that I can get some value in my application, the error that appears is 'test is not defined' and 'testejs is not defined' p>

Someone can help me, right away, thanks!

    
asked by anonymous 26.04.2017 / 01:08

2 answers

1

In your code, you are interrupting the before function from printing the content:

angular.module("NaBalada").controller("NaBaladaLocal", function(data){
    return $scope.teste = 'Testando Angular';
    console.log(testejs)
});

Nothing is processed after the keyword return , which ends the execution of the function. Try the following change:

angular.module("NaBalada").controller("NaBaladaLocal", function(data){
    console.log(testejs);
    $scope.teste = 'Testando Angular';
});
    
26.04.2017 / 21:30
0

I've managed to solve it in a way, I still do not know if it's the right way just for me to capture a geojson and play it in my database, I used the following way and it worked.

*//dentro do controle do angular*
angular.module("NaBalada").controller("NaBaladaLocal", function(){
    window.teste = 'Testando Angular';
    console.log(testejs);
});

*//Script normal JS*
console.log(teste);*//teste do $scope.teste*
window.testejs = 'Variável fora do angular, pra reconhecer dentro do controller'

I'll leave it there, it might help somebody.

    
26.04.2017 / 03:47