0
So... I’m making a code in Typescript in which I need to use a variable from another script, I’ll make it clear below:
<script type="text/javascript"> var global = "Variável Global";</script>
<script type="text/javascript" src="~/js/file.js"></script>
And inside the file.js I need to capture this variable, someone help me ?
Example:
file js.:
window.onload = function () {
alert(global);
}
(window as any).global
works?– Luiz Felipe
Where should I put this ? @Luizfelipe
– user149429
By accessing the global variable. By the way, edit your question by posting the code where you try to access the global variable so I have a little more context.
– Luiz Felipe
Then it would be so
alert(window!.global);
? @user140828– user149429
@Luizfelipe, the code is basically that right there, when the page loads, it gives the variable Alert
– user149429
You tried to
alert((window as any).variavelGlobalAqui)
?– Luiz Felipe
You can use
declare var global: tipo
.– Ghért B. König
It worked @Luizfelipe, thank you very much... could answer the question for people who have the same question in the future?
– user149429