'Pass content of ts variable in js file
I was wondering if it's possible to use the content of a ts variable and use it in js file ?
I'm feeling trapped now I realize that I don't know how can I achieve it.
Please send me any suggestion easy to implement if possible.
My ts file with the printedOption that I want to use in my js file.
The content of this variable is the value of my select input.
validateLuggages() {
this.printedOption = this.selectedOption;
this.http.get(`/routes/luggages`)
.subscribe((data) => {
this.parsedForLuggages = data;
})
return this.printedOption;
}
Now, How can I create the instance and use this variable in my JS file ?
Solution 1:[1]
To use any typescript variable inside javascript code you may firstly export the variable in typescript file which you want to use in the js file.
Then, you can simply use the import statement and import the variable from the correct path.
You can check the example below and refer the link for better clarity. LINK
// Add to tsconfig.json:
{ "compilerOptions": { ... "allowJs": true ... } }
import MyModule from './../pages/MyModule';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ashray Trivedi |
