Skip to content Skip to sidebar Skip to footer

Access Javascript Variable Included In HTML Header From Typescript

I have a javascript file included in the tags of my Angular 2 app. I would like to access a function in that javascript file from my typescript file, how

Solution 1:

Just declare it at the top of your component or wherever you need it like so:

declare var SimpleMDE: any;

Then you can call it in your constructor like you want!


Solution 2:

You can use namespacing, which is basically an object and it wraps all other variable & function

Like this

var SomeObject={}
SomeObject.abc = "Some Value";
SOmeObject.myFunction = function(){
  // function body
}

In other file you can simply call SomeObject.abc & it will return string Some Value

You should use namespacing to avoid conflict of global window


Post a Comment for "Access Javascript Variable Included In HTML Header From Typescript"