C
C
Cortc2015-05-27 21:32:38
JavaScript
Cortc, 2015-05-27 21:32:38

How to bind an angular service to an external asynchronous module?

There is an angular application and a separate module, suppose a video player flash library

FlashVideo.onTimeChange = function(currentTime){ /* doSomething */ }

What is the right way to implement this in terms of angular architecture and performance? The actions in the function are simple, but somehow tied to the angular application, plus the function is called quite often (several times per second).
So far, a few ideas have come up, but they all seem like crutches to me, or bad in terms of performance.
1) use $watch on $rootScope
2) notify via promise
3) $emit, $broadcast events

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-05-27
Protko @Fesor

use $watch on $rootScope

at you there event is launched, instead of the state of object changes. Stop shoving watches everywhere and everywhere
He's not for that. It is to notify that there will be a resolve soon.
exactly. You can make your own isolated scope to drive events only between two components, without affecting the rest of the system.

_
_ _, 2015-05-28
@AMar4enko

In addition to Sergey Protko 's answer - use throttling on the event

D
Dmitry Dedukhin, 2015-05-27
@Demetros

Do you need to update something in the application every time you call this function?
Is it possible to call digest not with every call, but for example once a second?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question