Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See input range value as it changes with Angular 2

Tags:

angular

Yes, this will be a noob question, because I'm a complete noob in Angular 2.

I'm trying to pass the value of a range to my component, I already figured out how. But now, I think that would be nice to see the value during the change and not while the change is made. I hope you understand what I'm trying to explain.

in app.component.html

<form action="#">
    <input type="text" placeholder="Time"><br>
    ram: {{ selectedRam }}
    <input #ramSelector name="ram" type="range" min="0" max="{{ ramMaxValue }}" (change)="setRam(ramSelector.value)" value="0">
</form>

in app.component.ts

setRam(value){
    this.selectedRam = value;
    console.log(this.selectedRam);
}

I found there is this "oninput" method, but didn't work.

Thansk in advance!

like image 245
Jorge Anzola Avatar asked Jan 18 '17 17:01

Jorge Anzola


1 Answers

Using input seems to work for me

<input type="range" min="0" max="100" #ranger (input)="yourMethod(ranger.value)">
like image 112
David Alsh Avatar answered Oct 25 '22 19:10

David Alsh