Fix lit-ts template (#1494)

* Fix lit-ts template

* Fixing generate Template

* Remove bad null check

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
NYSSEN Michaël 2022-06-27 12:56:18 +02:00 committed by GitHub
commit b2cec41fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 46 deletions

View file

@ -68,32 +68,31 @@ export class MyElement extends LitElement {
}
`
}
@property()
resultText = "Please enter your name below 👇"
@property()
resultText = "Please enter your name below 👇"
greet()
{
let thisName = this.shadowRoot.getElementById('name').value
Greet(thisName).then(result => {
this.resultText = result
});
}
greet() {
let thisName = (this.shadowRoot.getElementById('name') as HTMLInputElement)?.value;
if (thisName) {
Greet(thisName).then(result => {
this.resultText = result
});
}
}
render()
{
return html`
<main>
<img id="logo" src=${logo} alt="Wails logo">
<div class="result" id="result">${this.resultText}</div>
<div class="input-box" id="input">
<input class="input" id="name" type="text" autocomplete="off"/>
<button @click=${this.greet} class="btn">Greet</button>
</div>
</main>
`
}
render() {
return html`
<main>
<img id="logo" src=${logo} alt="Wails logo">
<div class="result" id="result">${this.resultText}</div>
<div class="input-box" id="input">
<input class="input" id="name" type="text" autocomplete="off"/>
<button @click=${this.greet} class="btn">Greet</button>
</div>
</main>
`
}
}
declare global {

View file

@ -68,32 +68,31 @@ export class MyElement extends LitElement {
}
`
}
@property()
resultText = "Please enter your name below 👇"
@property()
resultText = "Please enter your name below 👇"
greet()
{
let thisName = this.shadowRoot.getElementById('name').value
Greet(thisName).then(result => {
this.resultText = result
});
}
greet() {
let thisName = (this.shadowRoot.getElementById('name') as HTMLInputElement)?.value;
if (thisName) {
Greet(thisName).then(result => {
this.resultText = result
});
}
}
render()
{
return html`
<main>
<img id="logo" src=${logo} alt="Wails logo">
<div class="result" id="result">${this.resultText}</div>
<div class="input-box" id="input">
<input class="input" id="name" type="text" autocomplete="off"/>
<button @click=${this.greet} class="btn">Greet</button>
</div>
</main>
`
}
render() {
return html`
<main>
<img id="logo" src=${logo} alt="Wails logo">
<div class="result" id="result">${this.resultText}</div>
<div class="input-box" id="input">
<input class="input" id="name" type="text" autocomplete="off"/>
<button @click=${this.greet} class="btn">Greet</button>
</div>
</main>
`
}
}
declare global {