Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Using functions defined in typescript code from html

I have the following typescript files (pseudo code) Calculator.ts

export class calculator{
  someFunction
}

Main.ts

Import calculator from calculator.ts

function callSomeFunction()
{
  Calculator.somefunction();
}

Question: if tsc compiler bundles and generates code using systemjs or some other module syntax, will I be able to call callSomeFunction method from html which has bundle.js as script reference. If not then do I need to do window.callSomeFunction = callSomeFunction? Is there any other way?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The best way would be for the JavaScript to attach listeners to elements itself - for the JavaScript (your entire bundle) to depend on the HTML markup, but for the HTML markup to not (directly) depend on your JavaScript.

For example, instead of

<button onclick="doSomething()">click</button>

do

<button class="some-button">click</button>
// JavaScript that gets bundled
document.querySelector('.some-button').addEventListener('click', doSomething);

This way, doSomething doesn't need to be global, and you get to avoid inline handlers (which should never be used anyway).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda