JS scripts inside pages html files


#1

Hello,
Just getting the grips using Ionic and TS, I’m trying to include JS script inside my page html file. Is this possible? ATM the script seems to be being ignored. See below to what I mean:

<ion-header>
  <ion-navbar>
    <ion-title>
      About
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>

<script>

//DO JS HERE

</script>

</ion-content>

Thank you in advance,
Harry


#2

What are you really trying to achieve? There’s probably a more Ionic-natural way.


#3

In an other project I created some functions which takes the inputed text and coverts common words into Emojis using JS, this happens as the user is typing, using eventListeners etc.

Was wanting to incorporate this without having to convert it into TypeScript (as just learning). In my previous project this all took place within the script tags and I was wandering if i could do the same! I have tried adding the JS files into the header of my index.html file but get errors as my script uses getElementById, so if I link the script in the index.html it tries to find the element on each page and I only want it on one page.

I hope this makes sense


#4

I would try implementing this as a custom directive. Directly interacting with the DOM in an Angular world (which Ionic is) generally leads to pain, in my experience.