Browse Source

add debound time

pull/15/head
PhamY0601 1 year ago
parent
commit
a8c63b3f53
1 changed files with 12 additions and 5 deletions
  1. +12
    -5
      src/app/shared/component/slider-range/slider-range.component.ts

+ 12
- 5
src/app/shared/component/slider-range/slider-range.component.ts View File

Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import {debounceTime, Subject} from 'rxjs';


@Component({ @Component({
selector: 'app-slider-range', selector: 'app-slider-range',
@Input() max: number = 300; @Input() max: number = 300;
@Input() icon: string = ''; @Input() icon: string = '';
@Output() valueChange = new EventEmitter<number>(); @Output() valueChange = new EventEmitter<number>();
@Input() disable: boolean = false;
onChange = (value: number) => {}; onChange = (value: number) => {};
onTouched = () => {}; onTouched = () => {};
private valueChangeSubject = new Subject<number>();


constructor() {}
constructor() {
this.valueChangeSubject.pipe(debounceTime(500)).subscribe(value => {
this.valueChange.emit(value);
});
}


writeValue(value: number): void { writeValue(value: number): void {
this.value = value; this.value = value;
this.value = event.target.value; this.value = event.target.value;
this.onChange(this.value); this.onChange(this.value);
this.onTouched(); this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);
} }


onSliderChangeBackground() { onSliderChangeBackground() {
this.value += 10; this.value += 10;
this.onChange(this.value); this.onChange(this.value);
this.onTouched(); this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);

} }
} }


this.value -= 10; this.value -= 10;
this.onChange(this.value); this.onChange(this.value);
this.onTouched(); this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);
} }
} }
} }

Loading…
Cancel
Save