Currently focused on developing vertical sliders that can be manipulated by dragging them up or down independently

https://i.stack.imgur.com/NgOKs.jpg# I am currently working on vertical sliders that require dragging up and down individually. However, when I pull on the first slider, all sliders move together. The resetAllSliders button should also work independently, and the applyAllSliders button should apply changes.

HTML FILE

<div class="slider-container">
    <div *ngFor="let slider of sliders; let i = index" class="slider">
      <input type="range" [(ngModel)]="slider.value" (input)="onSliderChange(slider, i)" />
      <button (click)="resetSlider(slider)">Reset</button>
    </div>
  </div>
  <div class="button-container">
    <button (click)="resetAllSliders()">Reset All</button>
    <button (click)="applyAllSliders()">Apply All</button>
  </div>
  

TS File

// src/app/slider-app/slider-app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-slider-app',
  templateUrl: './slider-app.component.html',
  styleUrls: ['./slider-app.component.css']
})
export class SliderAppComponent {
  sliders: { value: number }[] = Array(3).fill({ value: 10 });

  onSliderChange(slider: { value: number }, index: number) {
    // Handle individual slider value change
    console.log(`Slider ${index} value changed to ${slider.value}`);
  }
  resetSlider(slider: { value: number }) {
    // Reset the individual slider to its default value
    slider.value = 10; // You can set the default value here
  }

  resetSliders() {
    // Reset all sliders to their default values
    this.sliders.forEach(slider => {
      slider.value = 10;
    });
  }

  applySliders() {
    
    console.log('Applying slider values:', this.sliders.map(slider => slider.value));
  }
}

Please provide assistance with above code for dragging sliders up and down individually

Answer №1

You must clearly distinguish these sliders from one another.

Within your component, introduce a new name property in addition to the existing value property.

custom-example.component.ts

type CustomSlider = {
  name: string;
  value: number;
};

@Component({
 ...
})
export class CustomExampleComponent {

  public customSliders: CustomSlider[] = [
    {name: 'A', value: 3},
    {name: 'B', value: 7},
    {name: 'C', value: 12}
  ];
}

custom-example.component.html

<div *ngFor="let slider of customSliders">
  <input type="range" [name]="slider.name" [(ngModel)]="slider.value">
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to emit a value from an observable once it is defined?

Is it feasible to create an observable that can wrap around the sessionStorage.getItem('currentuser')? This way, calling code can subscribe and retrieve the value only after it has been set in the sessionStorage. Do you think this is achievable? ...

Importing three.js using ES6 syntax

When it comes to working with ES6, my workflow involves using Babel and babel-plugin-transform-es2015-modules-system.js specifically to transform module import/export for compatibility with system.js. I rely on a "green" browser for most ES6 features excep ...

Tips for accessing several FormGroups within an Angular Reactive Form

Wondering if there is a method in Angular Reactive to access all FormGroups on the parent component. When I set a custom component that creates a new FormGroup within its own component, it does not reflect on the parent component. Is there a way to retri ...

Error message: "jQuery is not defined and occurs exclusively in Chrome."

I've been using the following code to asynchronously load my JavaScript in the head section: <script type='text/javascript'> // Add a script element as a child of the body function downloadJSAtOnload() { var element4= document.creat ...

A warning has been issued: CommonsChunkPlugin will now only accept one argument

I am currently working on building my Angular application using webpack. To help me with this process, I found a useful link here. In order to configure webpack, I created a webpack.config.js file at the package.json level and added the line "bundle": "web ...

Merge the JSON data with the Node.js/Express.js response

Whenever I input somedomain.com/some_api_url?_var1=1 in a browser, the response that I receive is {"1":"descriptive string"}. In this JSON response, the index 1 can vary from 1 to n, and the "descriptive string" summarizes what the index represents. I am ...

What is causing the ajax code to malfunction?

I am new to ASP MVC and trying to create a login form using AJAX. I have written a JsonResult in the controller to check the username and password, but for some reason it is not working. Here is my controller code: public ActionResult login() { ...

The table row disappears but the value persists

I have designed a table where users can perform calculations. However, when a row is deleted, the values from that row appear in the row below it and subsequent rows as well. What I want is for the user to be able to completely remove a row with its values ...

Continuously invoking a function until jQuery's .post method has completed loading

As I am diving into the world of jQuery framework, I encountered a situation where I used the readyState() function while working with AJAX in regular JavaScript to display a loading gif image. However, when transitioning to using jQuery's .post() met ...

Using JavaScript variables within an @if statement in Laravel within the innerHTML segment

How can I incorporate a JavaScript variable 'x' into an @if statement in Laravel? I have tried placing it both inside and outside of the @if statement. When placed outside, it works perfectly fine, but I really need to perform an action based on ...

AngularJS animation fails to activate

I've been working on a simple AngularJS application and I'm trying to add animations between my views. However, for some reason, the animation is not triggering despite following the tutorial on the AngularJS website. There are no errors in the c ...

Web pages that dynamically update without the need for reloading

Recently, I stumbled upon slack.com and was immediately captivated by its user interface. For those unfamiliar with it, navigating the site is quite simple: There's a sidebar on the left and a main content area on the right. When you click on an item ...

jQuery allows us to set two separate conditions for two distinct variables

I've written this function: settings_rc_left.on('click', function(){ var settings_list_last_element_id_one = settings_menu_element.attr('id') == 'r_02', settings_list_last_element_id_two = settings_menu_eleme ...

Submit file in Cypress while hiding input[type="file"] from DOM

Currently, I am conducting end-to-end testing on an Angular project that utilizes Ant Design (NG-ZORRO). In this project, there is a button with the class nz-button that, when clicked, opens the file explorer just like an input type="file" element would. W ...

Struggling to implement the UI router into my Angular Framework

I've been working on a framework that is supposed to be router agnostic. While I've managed to make it work with ngRoute, I just can't seem to get it functioning with UI Router. Here's a snippet of the main app module: (function () { ...

Tips for checking the type radio button input with Angular.js

I want to implement validation for a radio button field using Angular.js. Below is the code snippet I am working with: <form name="myForm" enctype="multipart/form-data" novalidate> <div> <input type="radio" ng-model="new" value="true" ng- ...

Using a dojo widget within a react component: A beginner's guide

Has anyone found a way to integrate components/widgets from another library into a react component successfully? For example: export default function App() { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + ...

Changing the CSS class of the Bootstrap datetime picker when selecting the year

Is there a way to change the CSS style of the Bootstrap datetime picker control so that when selecting years, the color changes from blue to red? I attempted to do this with the following code: .selectYear { background-color:red!important; } However ...

Conduct surveillance on the service function call within the constructor

I am currently facing a challenge with trying to monitor a service function call that is executed in the constructor. The test is straightforward, simply aiming to confirm that the function call is indeed made. beforeEach(async(() => { TestBed.con ...

Tips on restricting dates to be equal to or earlier:

I have written a code to determine if two given dates are equal or not. The code should allow for the current date to be smaller than or equal to the provided date, but it should not allow for it to be greater. var date = '10-11-2015'; var toda ...