rablentain
rablentain

Reputation: 6745

Building a range slider in Angularjs 2

I am using Angular 2 and I am trying to figure out how to replace all the things I usually do with jQuery. (Is there some nice article out there mapping jQuery to Angular 2?)

I would like to implement the range slider that is available in for instance the jQuery UI library: http://jqueryui.com/slider/#range.

I am starting out with this in my html:

<div class="bar">
    <div id="slider-range" style="background-color:black; width:20px; height:20px;" (mousedown)="moveRange($event)"></div>
</div>

And I want to be able to move the #slider-range to left and right, and it should be limited to the with of .bar.

In my controller:

moveRange() {
    console.log(event.clientX);
}

Which is where I got stuck. My first problem is, how do I modify the position of #slider-range using Angular?

Upvotes: 2

Views: 3535

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657957

I think using style binding is an easy ways to update the position of #slider-range

<div id="slider-range" [style.left]="calculatedLeft" style="background-color:black; width:20px; height:20px;" ngStyle= (mousedown)="moveRange($event)"></div>

For more complex style bindings you can use ngStyle

Upvotes: 1

Related Questions