Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have installed the angular-timer module on my application.

It works fine when I use it like the examples on that page, for instance, the code below yields the correct output:

<timer start-time="1357020000000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>

However, when I insert an expression inside the start-time attribute, I get this error

The expression {{order.lastUpdatedDate}} if used outside an attribute, correctly outputs the time in miliseconds, and if I copy-paste that result into an start-time attribute on the directive, it works!

So my guess is that this directive doesn't work with expressions... :(

I want to correct that, but I'm fairly new to Angular and I don't know how to begin.

Can anybody help me, or at least point a direction for me to research, please?

share|improve this question
up vote 4 down vote accepted

Try removing the {{ }}

<timer start-time="order.lastUpdateDate">
share|improve this answer
    
Wow... that was it! I'm feeling dumb right now haha . I think I might study how directives work so I don't make the same mistake again. thank you! haha – Matheus208 Apr 17 '14 at 16:33
    
Glad to hear it. Any attributes related to a directive should evaluate an expression and therefore don't need the template tags. – Steve Apr 17 '14 at 17:02

Here is a gotcha: the start-time attribute is evaluated only once during start.
In your example, order.lastUpdateDate might actually be calculated after the timer starts because it autostarts, so the timer will not show what you would expect.

There are a few ways to fix this:

  1. stop and start the timer after the value changed,
  2. Change the code to evaluate the start-time in the tick function (simplest approach,works for me)
  3. Change the code to set up a watch to detect when the start-time value changes and reevaluate it.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.