-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Labels
Description
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) {
var fromTime;
// Track changes to fromTime
scope.$watch('fromTime', function(value) {
fromTime = timeAgo.parse(scope.fromTime);
});
// Track changes to time difference
scope.$watch(function() {
return nowTime() - fromTime;
}, function(value) {
var elemHandle = 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');
}
}
});
}