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

217
Views
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 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>

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

over 4 years ago · Santiago Trujillo Report

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 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!