get value of slider with (change) of particular slider while using multiple sliders

Nikhil Radadiya

I have multiple slider in a component and i'm using nouislider

<nouislider [connect]="true"  [(ngModel)]="someValue" 
[config]="someKeyboardConfig" (change)="saveRange($event)"></nouislider>

<nouislider [connect]="true"   [(ngModel)]="someValue1" 
[config]="someKeyboardConfig" (change)="saveRange($event)"></nouislider>

component.ts

saveRange(value) {
    console.log('Value changed to', value);
  }

I get value on (change)` but don't know which slider value it is I have 7 slider like this in one page. How to know which sliders value it is. After getting slider range I want to write it in json file

Please suggest me a way here.

j6s

You have multiple options here:

1. pass an attribute to your method along with the event. This could look like the following:

HTML:

<nouislider [connect]="true"  [(ngModel)]="someValue" 
[config]="someKeyboardConfig" (change)="saveRange('first', $event)">     
</nouislider>

<nouislider [connect]="true"   [(ngModel)]="someValue1" 
[config]="someKeyboardConfig" (change)="saveRange('second', $event)">    
</nouislider>

JS/TS

saveRange(slider, value) {
   console.log('Value of ' + slider + ' slider changed to', value);
}

2. Simply use 2 methods

HTML:

<nouislider [connect]="true"  [(ngModel)]="someValue" 
[config]="someKeyboardConfig" (change)="saveSecondRange($event)">     
</nouislider>

<nouislider [connect]="true"   [(ngModel)]="someValue1" 
[config]="someKeyboardConfig" (change)="saveFirstRange($event)">    
</nouislider>

JS/TS

saveFirstRange(value) {
   console.log('Value of first slider changed to', value);
}
saveSecondRange(value) {
   console.log('Value of second slider changed to', value);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change slider bar color using setSliderColor on multiple sliders when using renderUI in R Shiny

Multiple sliders with Very Simple Slider

How to handle slider change event for multiple sliders in a page: JqueryMobile

How to change css file of bx-slider, multiple sliders on a page

Slick Slider Multiple Sliders retaining active position

Get value of slider while it's being moved?

jQuery sliders: only last slider working on page with multiple sliders

Using jquery slider to change filter blur value

Cannot change opacity value using Bootstrap slider

How to change value of style using a slider in jQuery

How change kCIInputBrightnessKey using slider value in Swift, I'm getting either white or black picture whatever value the slider get

Change value of bokeh slider

change slider value with interval

Change Slider Value with a Label

p5.js - updating slider value's in real time for multiple sliders

get cutom slider value using jquery

React-Native: Slider knob jumps to random position when using diffClamp and multiple sliders

get value of slider in typescript

Get label of slider to move with slider value

Javascript slider [rcarousel] - How to use multiple sliders at one website?

default slider which sets same value for all other sliders

Several sliders reacting to value output from a main slider

Get value from jQuery slider while it's moving

Change the color of jQuery slider multiple times when reaching a certain value

javascript slider error while using multiple slides in html

Change value of range slider dynamically

Bootstrap Slider change value handler

How To Change Grid Opacity using Slider Value In C#

Calculate multiple range slider value