javascript - ng-repeat without creating tags -
javascript - ng-repeat without creating tags -
i want dynamically generate rather boring <option> list of times <select>,
<select> <option>8:00am</option> <option>8:15am</option> <option>8:30am</option> <option>8:45am</option> <option>9:00am</option> <option>9:15am</option> <option>...</option> <option>5:00pm</option> </select> i know how generate minutes, i.e.
<option ng-repeat="minutes in ['00', 15, 30, 45]">8:{{minutes}}am</option> obviously need loop hours, create set of tags around every 4 <option>s, break <select>.
how can 1 ngrepeat without creating tags?
html:
<select> <option ng-repeat="h_m in [] track $index | time:8:20:15">{{h_m}}</option> </select> angularjs filter:
angular.filter('time', function() { homecoming function(input, from, to, interval) { = parseint(from, 10); = parseint(to, 10); interval = parseint(interval, 10); for(var i=from, y=0; i<=to; ++i, y+=interval) { for(var y=0; y<60; y+=interval) { input.push(((i % 12) || 12)+ ":" + (y===0?'00':y) +" " + (i>12?'pm':'am')); } } homecoming input; }; }); you can set start hour, end hr , interval:
time:start_hour:end_hour:interval
start_hour , end_hour must in 24 time format
interval in minutes , should between 1 , 59..
test here.
javascript angularjs angularjs-ng-repeat ng-repeat
Comments
Post a Comment