Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda