angular-timer icon indicating copy to clipboard operation
angular-timer copied to clipboard

Countdown not allowing dynamic value

Open analuisamartins opened this issue 9 years ago • 13 comments

Hi, I've not found a way to add a dynamic(scope) value in attr countdown. Ex: or (This way throws error in parsing) To fix this I changed the module directive adding the last line: (countdown: '=', and it works)

  scope: {
    interval: '=interval',
    startTimeAttr: '=startTime',
    endTimeAttr: '=endTime',
    countdownattr: '=countdown',
    countdown: '=',

I'm missing something? There is another way? Thanks.

analuisamartins avatar Jul 17 '14 23:07 analuisamartins

I am also having this issue. I'm trying to put a scope variable into the countdown attribute and it fails with this error:

Error: [$parse:syntax] Syntax Error: Token 'selectedNotification.countdown' is unexpected, expecting [:] at column 3 of the expression [{{selectedNotification.countdown}}] starting at [selectedNotification.countdown}}].

Tasemu avatar Jul 18 '14 03:07 Tasemu

However the fix doesn't appear to be working for me.

Tasemu avatar Jul 18 '14 03:07 Tasemu

The fix works without the {{ }} Ex: countdown="timeLimit"

analuisamartins avatar Jul 18 '14 09:07 analuisamartins

Same issue, same fix. The fix works without the {{ }}. Why don't you ask for a pull?

papasax avatar Dec 03 '14 18:12 papasax

Ask for pull, please.

lukasz-kaniowski avatar Dec 23 '14 12:12 lukasz-kaniowski

$scope.$broadcast 'timer-set-countdown', secs

This works.

pencilcheck avatar Dec 28 '14 13:12 pencilcheck

Adding an ng-if worked for me, ensuring the variable was ready to go before the directive was rendered.

So from:

<timer end-time="myVariable">{{minutes}} minute{{minutesS}}</timer>

To:

<timer ng-if="myVariable" end-time="myVariable">{{minutes}} minute{{minutesS}}</timer>

My example hasn't been tested for countdown, but I'm pretty sure it will translate.

I don't think that adding countdown: '=' would be a good way to do things, as this is already set up with countdownattr: '=countdown', and it is countdownattr that does all the magic.

You just need to delay rendering the directive until the point in the $digest cycle when your variable has been evaluated with an ng-if.

Hope this helps.

EDIT: More info on Angular's rendering cycle here: [ http://stackoverflow.com/questions/24615103/angular-directives-when-and-how-to-use-compile-controller-pre-link-and-post?rq=1 ]

FelixFortis avatar Apr 16 '15 15:04 FelixFortis

Yes this was the reason. The variable was not set yet. I fixed it using a django template variable instead of a angular variable which was not always set. Your method with ng-if sounds good too.

papasax avatar Apr 16 '15 17:04 papasax

@FelixFortis I tried that before, but the problem with that is first off end-time doesn't work at all, second, the moment it is assigned it will start with whatever time that was last rendered, then takes about a sec to update to the current value, meaning you will get a 1 or 2 sec flash. So this is not optimal in my opinion.

pencilcheck avatar Apr 18 '15 21:04 pencilcheck

+1 for ng-if solution....

h3nr1ke avatar Jan 29 '16 15:01 h3nr1ke

works fine: <timer ng-if="vm.countdown" countdown="vm.countdown"

NaN: <timer countdown="vm.countdown"

+1 for ng-if solution

wtczk avatar Mar 07 '16 14:03 wtczk

+1 for ng-if solution ..i tried many ways except ng-if...Wowww its worked perfectly

Miljokodiyan avatar May 27 '16 11:05 Miljokodiyan

👍 for @wtczk it work for me thanks you :)

hdung912 avatar May 18 '17 04:05 hdung912