0

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?

2 Answers 2

4

Try removing the {{ }}

<timer start-time="order.lastUpdateDate">
2
  • 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 Commented Apr 17, 2014 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. Commented Apr 17, 2014 at 17:02
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.