Created
May 20, 2018 12:58
-
-
Save realtomaszkula/29f00b3665576db8626de036e5de9244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormBuilder, FormGroup } from '@angular/forms'; | |
import { filter } from 'rxjs/operators'; | |
@Component({ | |
selector: 'app-price-range', | |
template: ` | |
<form [formGroup]="form"> | |
<mat-slider formControlName="rangeStart" thumbLabel min="1" max="5" step="0.5" value="1.5"></mat-slider> | |
<mat-slider formControlName="rangeEnd" thumbLabel min="1" max="5" step="0.5" value="1.5"></mat-slider> | |
</form> | |
`, | |
styleUrls: ['./price-range.component.css'] | |
}) | |
export class PriceRangeComponent implements OnInit { | |
form: FormGroup; | |
constructor(private fb: FormBuilder) {} | |
ngOnInit() { | |
this.form = this.fb.group({ | |
rangeStart: 0, | |
rangeEnd: 0 | |
}); | |
this.reactiveRange(); | |
} | |
reactiveRange() { | |
const startCtrl = this.form.get('rangeStart'); | |
const endCtrl = this.form.get('rangeEnd'); | |
startCtrl.valueChanges | |
.pipe(filter(v => v > endCtrl.value)) | |
.subscribe(v => endCtrl.setValue(v)); | |
endCtrl.valueChanges | |
.pipe(filter(v => v < startCtrl.value)) | |
.subscribe(v => startCtrl.setValue(v)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment