I am currently using a basic component within my form as shown below:
<app-slider [min]="field.min" [max]="field.max" [value]="field.min"></app-slider>
This component consists of the following code:
HTML:
<input #mySlider
class="slider"
type="text"
name="slider"
data-provide="slider"
data-slider-min="1"
data-slider-max="3"
[attr.data-slider-min]="min"
[attr.data-slider-max]="max"
data-slider-step="1"
[attr.data-slider-value]="value"
data-slider-tooltip="show"/>
TypeScript (ts):
import {Component, ViewChild, Input} from '@angular/core';
declare var $ : any;
@Component({
selector: 'app-slider',
templateUrl: './slider.component.html',
styleUrls: ['./slider.component.css']
})
export class SliderComponent{
@ViewChild('mySlider') slider: any; // can be ElementRef;
@Input() min: number;
@Input() max: number;
@Input() value: number;
constructor() { }
ngAfterViewInit() {
// slider is available
$(this.slider.nativeElement).slider();
let value = $(this.slider.nativeElement).attr("data-slider-value");
$(this.slider.nativeElement).slider('setValue', value);
}
}
I would like to implement NgModel on my component in order to access and modify its value:
<app-slider [min]="field.min" [max]="field.max" [value]="field.min" [(ngModel)]="currentValue"></app-slider>
Is there a way for me to accomplish this?