This is related to js scoping.

You can either bind this to the anonymous function like this:


<div>{{ time }} seconds ago</div>


<script>
 Polymer('timer', {,
 ready: function(){
 setInterval(function(){this.time++;}.bind(this), 1000)
 }
    });
</script>

Or you can set this to a variable:


<div>{{ time }} seconds ago</div>


<script>
 Polymer('timer', {,
 ready: function(){
   var _this_ = this;
   setInterval(function(){_this_.time++;}, 1000)
 }
    });
</script>

Either one should work

El domingo, 3 de agosto de 2014 00:23:44 UTC-3, [email protected] 
escribió:
>
>
> <div>{{ time }} seconds ago</div>
>
>
> <script>
>  Polymer('timer', {,
>  ready: function(){
>  setInterval(function(){this.time++;}, 1000)
>  }
>     });
> </script>
>
> Hi there,
>
> I'm new to this, so if I'm not  following posting guidelines very well, 
> apologies in advance.
>
> I simplified this code a little bit, but you get the idea. The issue with 
> the code is, because setInterval() requires me to create an anonymous 
> function, I can't access the custom element from there.
>
> Is there a way of reaching the custom element here? Or i there a way of 
> making a timing without setInterval()?
>
> Any help would be much appreciated.
>
> -officegunner
>
>

Follow Polymer on Google+: plus.google.com/107187849809354688692
--- 
You received this message because you are subscribed to the Google Groups 
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/944ea1e9-3900-4803-b97f-f3f74a5bcd70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to