0
I have a question, I have searched in other forums and I did not find the solution. I did a test on a code below just for demonstration.
*//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'
then my problem is that make the variables be seen inside and outside, so you can receive some value in my application, the error that appears is 'test is not defined' and 'testejs is not defined'
Someone can help me, from now on, thank you!
Why do you want to use it outside? I believe that they worked very well inside the controller, in addition if you were to use some element outside the scope 'Nabaladalocal', you would have to declare another controller and share information between them.
– Felipe Duarte
I’m using a library to generate polygons and I had to do this outside the angle, and to insert it into my database using the angular $http.post.. but for this I have to make the angular recognize the variaces that are in my script js.
– Pedro Lucas Lima
I get it, you’re using a global variable which is very dangerous kk, I recommend you read this https://answall.com/questions/32251/vari%C3%A1vel-global-in-javascript
– Felipe Duarte
So I took a look, but I still couldn’t accomplish what I wanted. I think the best way for me to try to clarify how it works would be, where you have //normal JS script; compare it as a second file. the first part
teste1.js
and the second partteste.js
who carry in the sameindex.html
. but when I declare for examplevar tst2 = "Teste"
when I sayconsole.log(tst2)
inside my angular controller it does not recognize. and gives what I have already reported in the question. :/– Pedro Lucas Lima