Choose class by current date in angularjs -
i have icon, , need change color if modified date = current date.
logic: if inventory.modified = time
apply style.
in controller :
$scope.time = new date();
template: <span class="glyphicon glyphicon-ok-sign" ng-class=""></span>
api modified: modified: "2014-04-07t13:04:25.676000",
you need change logic little bit.
looking @ timestamp format, style applied 1/100000th of second. think chance javascript running @ exact time pretty low.
you want 1 of following:
apply style if same minute
apply style if time matches , remove after specified interval (say, 15 seconds)
either way, date
filter should usefull: http://docs.angularjs.org/api/ng/filter/date
edit:
in js:
// once, don't need convert again $scope.time = $filter('date')(new date(), 'shortdate'); ... inventory.$modified = $filter('date')(new date(inventory.modified), 'shortdate');
in template:
<span ng-class="active: inventory.$modified == time"> {{ inventory }} </span>
although, performance precalculate field inventory.$modifiedtoday
(=true/false) each iteration not need recalculate. template this:
<span ng-class="active: inventory.$modifiedtoday"> {{ inventory }} </span>
Comments
Post a Comment