I'm in the process of creating a straightforward directive for a date countdown. However, I've hit a roadblock with this particular error:
Syntax Error: Token '21' is an unexpected token at column 12 of the expression [2013-08-28 21:10:14] starting at [21:10:14]
I honestly have no idea how to resolve it.
Here's a link to my example on jsfiddle:
And here's the CoffeeScript version since the JavaScript one is just too lengthy:
.directive "timer", ["$compile", ($compile) ->
restrict: "E"
replace: false
scope:
endTimeAttr: "=endTime"
controller: ($scope, $element) ->
_second = 1000
_minute = _second * 60
_hour = _minute * 60
_day = _hour * 24
timer = undefined
showRemaining = ->
now = new Date()
distance = end - now
if distance < 0
clearInterval timer
setExpired "EXPIRED!"
return
$scope.days = Math.floor(distance / _day)
$scope.hours = Math.floor((distance % _day) / _hour)
$scope.minutes = Math.floor((distance % _hour) / _minute)
$scope.seconds = Math.floor((distance % _minute) / _second)
setExpired = (value) ->
content = angular.element("<div></div>").html(value).contents()
compiled = $compile(content)
element.html ""
element.append content
compiled scope
end = new Date($scope.endTime)
timer = setInterval(showRemaining, 1000)
]