Javascript function in typescript file

hi,
i’m in ionic 3 and i want to call a javascript code from my html page but my ionic html page isn’t the main html page so i don’t have header tag to use script tags. it just looks like something like this:

<ion-header>
   <ion-item>


so how can i call a javascript code?can i write it in typescript file and call it by event in a button for example?if yes how?
thanks for your attention

Start with reading this Docs

You should expand your foundation with Ionic, TypeScript and Cordova to keep progressing. There are several great resources out there that will help you get up to speed. See: https://ionicframework.com/docs/developer-resources/

thanks for answering but unfortunately i couldn’t find my answer in those documents…there isn’t any specific point to my question any where.

What they mean is: It looks like you’re not getting the big picture of using/scripting/coding in TypeScript/Ionic/Angular.

Try to understand in which environment you’re working in. You can find enough tutorials for beginners are out there on the www. Therefor; please do read the docs, follow some tutorials and try to learn/understand.

hello,
in priciple an Ionic app is an angular app. Ionic 3 provides some tooling.
So you do not work directly with the angular cli, instead you use the ionic cli like ionic serve. Also Ionic 3 provides components, directives and wrappers for native plugins.

So you can use any angular (not angularjs) tutorials to see how it works on html side and how it communicates with/from ts side. An often read advice is, do not manipulate dom by yourself, use the concepts of angular.

A complete tutorial is https://angular.io/tutorial
Often it is for a beginner easier to fllow tutorials shorter tutorials like Josh Moronys tutorials.

Most of js is valid ts. ts transpiles all to js. So you can use js in typescript. Better is learning typescript, it is not so much. https://www.typescriptlang.org/docs/home.html
For example on ts you should use let instead of var, as long as you need var explict.

an example on html side

<button ion-button (click)='alertme()'><button>

is the html element, ion-button is a directive, (click) describes the event handler and alertme() is the methode that is called on ts side.

On ts side you have for example

alertme(){
alert('autsch');
}

Best regards, anna-liebt

2 Likes