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

216
Vistas
How to add simple onchange events on Angular 2 components

I have the component file and its templateURL html file.

In the html file I have the following code:

 <input type="range" min="0" max="20" value="0" step="1" change="showValue(this.value)" />
    <span id="range">0</span>

In the component, I have this code:

ngAfterviewInit(){
    function showValue(newValue){
        document.getElementById("range").innerHTML=newValue;
    }
}

I put the function in there, but it says its not defined. I am not sure how to define the function, and how to call it in the html file.

Any ideas? Thanks in advance, I'm quite new to A2.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

<div ng-app="">
<input type="range" min="0" max="20" value="0" step="1" ng-model="rangenumber" />
<span ng-bind="rangenumber" id="range">0</span>
</div>

Component events Read this article https://toddmotto.com/component-events-event-emitter-output-angular-2

over 4 years ago · Santiago Trujillo Denunciar

0

You can use ngmodel to bind your value and bind the same to span.No need to define any new functions.Please see below.

 <input type="range" min="0" max="20" [(ngModel)]="variable" step="1"  />
 <span id="range">{{variable}}</span>

you need to declare variable at component side.

Hope it helps!!

over 4 years ago · Santiago Trujillo 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