I would like to call a TypeScript (ultimetely JavaScript) function from HTML. The Problem is that I would also like to use a module System (systemjs, commonjs etc.) and also webpack.
Here is an example:
example.ts:
export class Example {
myFunction() {
alert('Test');
}
}
example2.ts:
export function doSomething() {
alert('Test2');
}
example.html:
<html>
<head>
<script src="path/to/the/compiled/js/file.js"></script>
<script>
$(document).ready(function() {
$('#test-btn').click(function(){
var example = new Example(); //error1
example.myFunction();
});
});
</script>
</head>
<body>
<button id="test-btn">Click me</button>
<a href="javascript:doSomething()">Click me too</a> <!-- error2 -->
</body>
</html>
The error comments indicate where the Errors happen: The exported class/function is not found because a module System is used. If I look into the compiled js files I can see that the class and function declarations are put within some module functions, so they are not accessible from HTML.
Currently I am using a Workaround by moving the entire $(document).ready...
section into a TypeScript file. But for the <a href...
example I don't have any Workaround.
So my final question: Is it actually possible to call a TypeScript function/class from HTML and using a module System?
message
events. those would broadcast to your typescript app. – Fourdimensionalwindow
object unpolluted and separates your concerns. – Fourdimensional