Phonegap Android Websocket with Angularjs

137 views
Skip to first unread message

José Leal Domingues Neto

unread,
Mar 22, 2013, 1:28:48 PM3/22/13
to ang...@googlegroups.com
Hello Experts,


I'm receiving a callback from a Java interface which is embedded in my javascript. From this callback I receive a String to be processed by my Javascript code in the client. The whole app is built in angular.

The problem is that, everytime I receive this callback from this Android Java interface, it seems to me that angularjs is creating somehow a second $scope, where everything is not visible to the 'normal' scope.
An example is inside the question, but I'll explain quickly. I set up a timer simply outputting a number set in a service every 5 seconds. The WebSocket callback changes this number to 2.

Output before the callback:
n: 1
n: 1
n: 1
n: 1

As soon as the Websocket callback calls, it then outputs my alternately 2 times the different numbers.

Output after the callback:
n: 1
n: 2
n: 1
n: 2
n: 1
n: 2
n: 1
n: 2


Strange, huh? I don't know what is angular really doing, but it works perfectly if I change a variable in a global scope, window.myNumber for example.
I am calling $rootScope.$apply , so it shouldn't be the problem.

If you could help me would be very nice ;D

Thank you all,
Jn
Reply all
Reply to author
Forward
0 new messages