I have created two dropdowns Opening hours & Closing Hours using ng-options, in angularJS. The drop-down options get populated by same array $scope.availableTimes
Below is the HTML code:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="exampleFormControlSelect1">Opening </label>
<select class="form-control" data-ng-options="time.display for time in availableTimes" data-ng-model="selectedFromTime">
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleFormControlSelect1">Closing</label>
<select class="form-control" data-ng-options="time.display for time in availableTimes" data-ng-model="selectedToTime">
</select>
</div>
</div>
</div>
Below is the AngularJS script
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.availableTimes = [];
$scope.availableTimes.push({
'msValue': 0,
'display': '12:00 Morning'
});
for (var msValue = 900000; msValue <= 85500000; msValue += 900000) { // 90.000ms = 15 min, 85.500.000ms = 11:45PM
$scope.availableTimes.push({
'msValue': msValue,
'display': moment(msValue).utc().format("h:mm A")
})
}
var dayMS = 86400000 - 1;
$scope.availableTimes.push({
'msValue': dayMS,
'display': '12:00 Midnight'
});
console.log($scope.availableTimes);
});
As you can see both dropdown now has the list of times starts from 12:00 Midnight to 12: 00 Morning with 15 mins interval.
like this:
12:00 Morning
12:15 am
12:30 am
12:45 am
.....
.....
11:45 pm
12:00 Midnight
What I can do to make the Closing Hour drop-down options lists starts with the value that is 15 min greater than Opening hours.
Example:
If opening hours selected as 8:00 am Closing hours dropdown list will start from 8:15 am instead of 12:00 Morning.
Opening Hours
12:00 Morning
....
....
8:00 am (Selected)
8:15 am
8:30 am
....
12:00 Midnight
Closing hours
8:00 am
8:15 am
8:30 am
.......
.......
12:00 Midnight
12:15 am
12:30 am
.......
.......
7:45 am
I hope the example gives the idea what I'm trying to achieve. Any help will be appreciated.