Rehan
Rehan

Reputation: 441

using AngularJS slider for getting date input as range

I am working with AngularJs and AngularMaterials and i want the user in my application to define the date input as a range in something in the following format(2016-01-01T00:00:00). How can a AngularJS slider be modified to be used for date inputs?

Upvotes: 1

Views: 1474

Answers (1)

Agam Banga
Agam Banga

Reputation: 2693

I have added an example on jsfiddle

HTML

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.js"></script>
<script src="https://rawgit.com/rzajac/angularjs-slider/master/dist/rzslider.js"></script>
<div ng-app="rzSliderDemo">
    <div ng-controller="MainCtrl" class="wrapper">
        <article>
            <rzslider  rz-slider-model="slider.minValue"
          rz-slider-high="slider.maxValue"
          rz-slider-options="slider.options"></rzslider>
        </article>
        </div>
        </div>

JAVASCRIPT

var app = angular.module('rzSliderDemo', ['rzModule', 'ui.bootstrap']);

app.controller('MainCtrl', function ($scope, $rootScope, $timeout, $modal) {
var date1 = new Date(2017, 3, 1);
var date2 = new Date();
var day;
var dateArray = [date1];
while(date1 <= date2) {
    day = date1.getDate()
    date1 = new Date(date1.setDate(++day));  
    dateArray.push(date1);
}
$scope.slider = {
   minValue: dateArray[0],
  maxValue: dateArray[dateArray.length-1],
  value: dateArray[0], // or new Date(2016, 7, 10) is you want to use different instances
  options: {
    stepsArray: dateArray,
    translate: function(date) {
      if (date != null)
        return date.toISOString();
      return '';
    }
  }
};
});

Upvotes: 2

Related Questions