Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use TypeScript on a button click

Tags:

typescript

I am trying to use typescript in my application. for the same I am doing an POC and in POC i want to call a function Defined in TypeScript class on button click.

Is it possible to call the function? If yes then how?

So far I have seen examples where the functions are called on Page load only. I need to call a function on certain event.

Thanks.

like image 713
Himanshu Porwal Avatar asked Aug 06 '14 04:08

Himanshu Porwal


1 Answers

I need to call a function on certain event.

If the function is global e.g. TypeScript:

function foo(){
   alert('foo');
}

Just use onclick e.g. html:

<button onclick="foo()">click me!</button>

Remember TypeScript is (almost) JavaScript.

However I recommend using a framework like angular with TypeScript. For maintainability. As an example take a look at the browser quickstart.

like image 175
basarat Avatar answered Nov 09 '22 14:11

basarat