Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Cómo agregar eventos onchange simples en componentes Angular 2

Tengo el archivo del componente y su archivo html templateURL.

En el archivo html tengo el siguiente código:

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

En el componente, tengo este código:

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

Puse la función allí, pero dice que no está definida. No estoy seguro de cómo definir la función y cómo llamarla en el archivo html.

¿Algunas ideas? Gracias de antemano, soy bastante nuevo en A2.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

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>

Eventos de componentes Lea este artículo https://toddmotto.com/component-events-event-emitter-output-angular-2

over 4 years ago · Santiago Trujillo Report

0

Puede usar ngmodel para vincular su valor y vincularlo a span. No es necesario definir ninguna función nueva. Consulte a continuación.

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

necesita declarar la variable en el lado del componente.

¡¡Espero eso ayude!!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!