1

I am using a slider in Angular 4. Below is my code in HTML:

  <div oninput="range1value.value = range1.valueAsNumber" id="range">
                    Actual/Optimised
                    <input name="range1" type="range" step="1" min="1" max="3" value="1" (onRangeChanged)="onRangeChange"> Adjusted
                    </div>

I want the slider to trigger a function Max() when it is on the maximum range and I want it to trigger separate function Min() when it is on the minimum range. Please help.

Regards

Neha

7
  • You don't need to make two functions because you can handle this inside the function by checking the value of the input. Commented Jan 3, 2018 at 10:35
  • @SurjeetBhadauriya I am new to angular. How can i achieve it? Commented Jan 3, 2018 at 10:51
  • I have added the answer. Please go through with that. Commented Jan 3, 2018 at 11:39
  • @SurjeetBhadauriya Fantastic.Thank you. Commented Jan 4, 2018 at 6:48
  • Pleasure @Neha. Please mark it right. Commented Jan 4, 2018 at 6:53

1 Answer 1

1

You can achieve this thing by making a function in the component.

Component

In the below function, you can do whatever you want.

  onChangeRange(rangeValue: any){
    console.log(rangeValue);
    if(rangeValue == 1){
       //do something
     }else if(rangeValue == 3){
       //do something else
     }else{
       //do something else
     }
  }

HTML

<input name="range1" type="range" step="1" min="1" max="3" [(ngModel)]="rangeValue" (change)="onChangeRange(rangeValue)"> Adjusted

Explanation

rangeValue: this contains the value of the range.

onChangeRange: this is a function which will call when you change the range.

Sign up to request clarification or add additional context in comments.

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.