Broadcast from legacy code to Angular via rootScope
-
03-07-2021 - |
Frage
I am trying to broadcast a message from legacy javascript function into Angular controller(s) via a Angular service. Broadcasting works fine when called within Angular, but not outside. See http://jsfiddle.net/yh3Ds/24/
Lösung
It seems that angular.injector()
is creating new module instance and
it is independent from the module instance bound with the html via ng-app
attribute.
So solution is to use manual bootstrap and obtain the injector there.
Use this injector you can access the service instance and $rootScope
which
is actually controlling the view.
Here is the updated fiddle; http://jsfiddle.net/d8vX3/1/
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow