As the title says, I have a table which one of the columns is an epoch date. I am trying to use javascripts built in 'toISOString()` to translate it, but can't figure out how to do it. IS there a way to do it on the fly while populating the table?
Here is the js for what I am working with:
angular.module('myapp', [])
.controller('MainCtrl', function($scope, $http, $filter, $interval) {
var orderBy = $filter('orderBy');
$scope.savedOrder = 'name';
$scope.searchText = ''
//first http request-----------------------------------
$http.get('xxxxxxxxxxxxxx').success(function(data) {
$scope.recentalerts = data;
$scope.tempdata = data;
$scope.order('-epochtime');
});
$scope.reverse = true;
//beginning of interval--------------------------------
$interval(function() {
$http.get('xxxxxxxxxxxxx').success(function(data) {
if (!angular.equals(data, $scope.tempdata)) {
console.log("here...");
...
$scope.tempdata = data;
} //end if
});
}, 5000);
$scope.order = function(predicate) {
$scope.reverse = !$scope.reverse;
$scope.recentalerts = orderBy($scope.recentalerts, predicate, $scope.reverse);
$scope.savedOrder = predicate;
};
});
And here is the table body :
<tbody>
<tr data-ng-repeat="alert in recentalerts | orderBy:savedOrder:reverse | filter:searchText">
<td ng-click="search(alert.epochtime)">{{alert.epochtime}}</td>
<td ng-click="search(alert.ip)">{{alert.ip}}</td>
<td ng-click="search(alert.type)">{{alert.type}}</td>
<td ng-click="search(alert.classification)">{{alert.classification}}</td>
</tr>
</tbody>
I tried {{alert.epochtime.toISOString()}}
but that didn't work. I guess it needs to be a date object before I do the toISOString()
but is there a way to do that inside the ng-repeat
?