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:

  1. apply style if same minute

  2. 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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -