Possible to pass value from index.html to main.ts?

I have some variables I want to edit in index.html js to the main ts. For example: a=1 is initiated in main.ts; and I want to edit it in index.html, so that the a=2 instead. Is it possible? Thanks!

Original Post on Discord

by user 204651044183998464

You can edit js variables of course. Can you elabroate how you want to modify it from index.html. You need to have some javascript in place for that (for example via a button)

One easy way would be to initialize your variable in global scope (which can get quite difficult to debug if you do that a lot but just for illustration)

in main.ts:

let myValue = 1;

and in another script in your index.html

<script>
myValue = 10;
</script>

I have used the globalthis in my index html and able to access them in both my needle script and main.TS.

by user 204651044183998464