You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed a way to style values based on them being past or future. Not sure if this is the correct way to do this but I found it very useful. Hopefully this information can help someone else who needs it.
link: function(scope,elem){varfromTime;// Track changes to fromTimescope.$watch('fromTime',function(value){fromTime=timeAgo.parse(scope.fromTime);});// Track changes to time differencescope.$watch(function(){returnnowTime()-fromTime;},function(value){varelemHandle=angular.element(elem);elemHandle.text(timeAgo.inWords(value,fromTime,scope.format));if(fromTime<nowTime()){if(elemHandle.hasClass('time-ago-future')){elemHandle.removeClass('time-ago-future');}if(!elemHandle.hasClass('time-ago-past')){elemHandle.addClass('time-ago-past');}}else{if(elemHandle.hasClass('time-ago-past')){elemHandle.removeClass('time-ago-past');}if(!elemHandle.hasClass('time-ago-future')){elemHandle.addClass('time-ago-future');}}});}
The text was updated successfully, but these errors were encountered:
The current implementation can be quite consuming as the watcher would be executed at every cycle. One idea to make it better, if the date has not changed and is already in the past, no need to check for the classes.
Also, I think this enhancement may not be a timeago feature but a separate directive that works directly on the date. I think the 2 feature should not be linked into a single directive as they are for 2 separate concerns. @yaru22 any though about that ?
I needed a way to style values based on them being past or future. Not sure if this is the correct way to do this but I found it very useful. Hopefully this information can help someone else who needs it.
The text was updated successfully, but these errors were encountered: