Reputation: 441
I have created a date range slider using AngularJS and Angular materials but currently i am able to return the min and max value of the date range as single variable however i want to store and return these values through two seperate variable which are to be used in a POST request later.
e.g.
var a : 2016-01-01T00:00:00
var b: 2018-01-01T00:00:00
Here is the working fiddle for the current code.
https://jsfiddle.net/rehan516/m0ygxvdj/
HTML
<script src="https://rawgit.com/rzajac/angularjs-slider/master/dist/rzslider.js"></script>
<div ng-app="rzSliderDemo">
<div ng-controller="MainCtrl" class="wrapper">
<article>
{{slider.minValue}}
{{slider.maxValue}}
<rzslider rz-slider-model="slider.minValue"
rz-slider-high="slider.maxValue"
rz-slider-options="slider.options"></rzslider>
</article>
</div>
</div>
JS
var app = angular.module('rzSliderDemo', ['rzModule', 'ngMaterial','ngAnimate','ngAria']);
app.controller('MainCtrl', function ($scope, $rootScope) {
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();//returning date range
return '';
}
}
};
});
POST QUERY
{
"query": {
"bool": {
"must": [
{
"range": {
"metadata.o2r.temporal.begin": {
"from": "2016-01-01T12:35:41.142Z"
}
}
} ,
{
"range": {
"metadata.o2r.temporal.end": {
"to": "2016-12-30T22:00:00.000Z"
}
}
}
]
}
}
}
'
Upvotes: 2
Views: 1088
Reputation: 441
The suggestions in the comments worked fine. This is how i updated the `$scope.slider section in my JS file .
$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)
lower =$scope.slider.minValue;
upper =$scope.slider.maxValue;
return date.toISOString();
}
}
};
i added two new variables and then passed these to my POST
request.
Upvotes: 2