I have MySQL table called events:
id| descr | time_from | time_to |
1 | wake up | 10:00:00 | 10:15:00 |
2 | play | 11:00:00 | 12:00:00 |
3 | walk | 14:00:00 | 14:30:00 |
I loop throught this table using ng-repeat and I've try to apply own filter, that should filter events by current time. So as you can guess, with this filter only one event should be displayed. Below you can see, what I have tried to do.
This is how I select events and prepare json for angular:
<?
mysql_connect("localhost","root","");
mysql_select_db('organaizer');
$sql = mysql_query('SELECT * FROM events');
while($lesson = mysql_fetch_array($sql))
{
$rows[] = $lesson;
}
print json_encode($rows);
?>
Events shows up well with no errors. Angular code:
function eventsCtrl($scope, $http)
{
$http({method: 'POST', url: 'events.php'}).success(function(data)
{
$scope.events = data; // response data
});
$scope.currentTime = function(lesson)
{
//Filter by current time
}
}
The markup:
<div class='well' style='margin:10px;' ng-app ng-controller="eventsCtrl">
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th>#</th>
<th>Event</th>
<th>Start at</th>
<th>End at</th>
</tr>
<tr ng-repeat="event in events | filter:currentTime">
<td>{{event.id}}</td>
<td>{{event.descr}}</td>
<td>{{event.time_from}}</td>
<td>{{event.time_to}}</td>
</tr>
</table>
</div>
So, I've tried to apply filter using the example of $interval on angularjs.org using time format "HH:mm:ss", but unfortunately this doesn't help.
Maybe you have better ideas how to do this.
time_fromandtime_to(Strings, Dates,...)? Are you sure yourcurrentTimefunction gets called?time_fromandtime_tois string. And I'm completly sure, thatcurrentTimebeing called.