我正在为日期倒计时构建简单的指令。但我被困在这个错误上
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]
真的不知道如何让它工作
这是我在 jsfiddle 上的示例
这是咖啡脚本,因为在 javascript 中它的代码太多:(
.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)
]