Skip to content

Instantly share code, notes, and snippets.

@hatemhosny
Created November 1, 2021 23:50
Show Gist options
  • Save hatemhosny/406b6775436e136cb913ad3376f411b2 to your computer and use it in GitHub Desktop.
Save hatemhosny/406b6775436e136cb913ad3376f411b2 to your computer and use it in GitHub Desktop.
TypeScript Demo (for testing import)
<div class="container">
<h1>Hello, <span id="title">World</span>!</h1>
<img class="logo" src="http://127.0.0.1:8080/livecodes/assets/templates/typescript.svg" />
<p>You clicked <span id="counter">0</span> times.</p>
<button id="counter-button">Click me</button>
</div>
class Counter {
private count: number;
constructor() {
this.count = 0;
}
increment() {
this.count += 1;
}
getValue() {
return this.count;
}
}
const title = document.querySelector("#title");
const count = document.querySelector("#counter");
const button = document.querySelector("#counter-button");
title.textContent = "TypeScript";
const counter = new Counter();
button.addEventListener(
"click",
() => {
counter.increment();
count.textContent = String(counter.getValue());
},
false
);
.container,
.container button {
text-align: center;
font: 1em sans-serif;
}
.logo {
width: 150px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment