angular-slider / ngx-slider

Self-contained, mobile friendly slider component for Angular based on angularjs-slider
https://angular-slider.github.io/ngx-slider/
MIT License
387 stars 175 forks source link

slider does not update form control value when dragging #81

Open matthiasferraina opened 5 years ago

matthiasferraina commented 5 years ago

Hello,

I am dealing with an issue. I have tested the reactive form module demo in my angular application. Every thing works fine, except that the form control value does not update when dragging as it is on the demo example. I have to release the slider pointer to make the form control value updated.

I don't really know if it is an issue. But i prefer to ask :)

I am currently working with this angular conf :

"dependencies": { "@angular/animations": "~7.0.0", "@angular/common": "~7.0.0", "@angular/compiler": "~7.0.0", "@angular/core": "~7.0.0", "@angular/forms": "~7.0.0", "@angular/http": "~7.0.0", "@angular/platform-browser": "~7.0.0", "@angular/platform-browser-dynamic": "~7.0.0", "@angular/router": "~7.0.0", "@ng-bootstrap/ng-bootstrap": "^4.0.0", "angular2-loaders-css": "^2.0.1", "angular2-moment": "^1.9.0", "bootstrap": "^4.1.3", "core-js": "^2.5.4", "ng5-slider": "^1.1.13", "ngx-cookie-service": "^2.0.0", "rxjs": "~6.3.3", "zone.js": "~0.8.26" },

piotrdz commented 5 years ago

Can you provide an example of what is not working? A StackBlitz reproduction would be perfect.

piotrdz commented 5 years ago

@matirmv Can you please re-test with v1.2.0 ? I suspect this might be fixed now.

mpschaeuble commented 3 years ago

Not sure if its the same problem, but in my case the userChangeEnd is not always executed last. As a consequence, my userChangeEnd event handler read deprecated values from the reactive form model. As a workaround, I'm writing back the current slider values to the form model manually before my userChangeEnd event handler runs:

(userChangeEnd)="writeSliderValuesToForm($event); handleEventFilterChanged()"
writeSliderValuesToForm(changeContext: ChangeContext) {
    this.formGroup.controls.slider.setValue([changeContext.value, changeContext.highValue])
}

handleEventFilterChanged() {
    console.log('reading the correct form values', this.formGroup.value.slider[0], this.formGroup.value.slider[1]) 
}