#The Angular Way of Repeating an Action

19 messages · Page 1 of 1 (latest)

hasty zephyr
#

What's the "Angular way" to start a repeated action? Instead of using something like setInterval() for example.

ruby socket
#

Observables. timer or interval probably. But specifics matter

hasty zephyr
#

it was for the purpose of canvas animation. but I'm just going to use requestAnimationFrame

hasty zephyr
#

oh awesome

#

thanks

#

does this need to be ran in NgZone?

ruby socket
#

Depends

hasty zephyr
#

it changes properties on this.ctx

#

so I would assume it triggers the change detection

#

oh I see, I should pass the canvas ctx as the state paramater to the work function instead of binding this

errant rivet
#

Zone will do it automatically 🙂

ruby socket
#

I would have assumed you wouldn't want Angular Zone involved in animations. But I also wouldn't want animations in Angular beyond CSS. So I have no idea what you are doing. Seems like you are coming from an entirely different direction to Angular than the one I am familiar with.

errant rivet
#

If I was animating something, I would run entirely outside the Angular Zone and directly mutate the DOM on the target (not relying on Angular data binding at all)

hasty zephyr
#

but what if the data im animating has some reliance on angular bound data?

#

i ended up just running it in zone and using set interval with requestAnimationFrame, i'll have to make sure its not triggering change detection every render frame though

errant rivet
#

If it's in the zone, it is.

hasty zephyr
#

hmm.. alright

#

i currently have a setInterval calling a component function bound to this thats running outside of angular