5

I'm working on an Ionic 2 app and playing around with the range, as described here: https://ionicframework.com/docs/v2/api/components/range/Range/

Call me crazy, but I can't find anywhere on google how the range component can call a method in my .ts class once the value has changed.

Something like a button, which goes like this:

<button ion-button (click)="myMethod($event)">

Of course, I need the value of the slider. In my case I defined it as follows:

  <ion-range min="0" max="10" color="danger">
    <ion-label range-left>0</ion-label>
    <ion-label range-right>10</ion-label>
  </ion-range>

Anyone got an idea?

2 Answers 2

8

The answer is right in the docs in the section output-events:

ionChange Expression to evaluate when the range value changes.

Use it as follows:

<ion-range min="0" max="10" color="danger" (ionChange)="myMethod($event)">
  <ion-label range-left>0</ion-label>
  <ion-label range-right>10</ion-label>
</ion-range>
Sign up to request clarification or add additional context in comments.

1 Comment

I feel silly.. Must have had my eyes closes while I browsed through the docs. Thanks mate.
1

Try in this way.

public myMethod(newRangeValue){
 console.log("Range :"+newRangeValue); 
}
<ion-range min="0" max="10" color="danger" [(ngModel)]="modelRange" (ionChange)="myMethod($event)">
  <ion-label range-left>0</ion-label>
  <ion-label range-right>10</ion-label>
</ion-range>
New value : {{modelRange}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.