0

Im trying to share data between 2 views. I need to use the 2 views at the same time on two different machines. One is controlling the other(ex: a counter) 1st view has next(+1) and the other just displays the result. I want the data to synchronized/binded. I do not want to have to refresh the 2nd page or to have to pull data with a timer or otherwise.

My idea was to use ng-view and routeProvider, I know that when the view changes the scope is cleared so I tried to use a parent controller/scope, the data is shared but I have to refresh the page on my 2nd view. I tried a service, same thing. I tried to $watch the result of the service but on the second controller/view no event is picked up so the view doesn't update.

what is the way to go? I was thinking about broadcasting or emit a custom event and trying to catch it, will that work? Am I just not binding to the service correctly? Would ui-router work better? I feel there should be an easy way to do this.... Im not seeing it! Please help if you can.

ng-mad
  • 3
  • 2
  • 1
    If you want to do this on two different machines you need some form of communication between those machines. Have a look at angularfire.com – Pieter Herroelen Apr 11 '14 at 07:06
  • Thanks for all inputs, I'm looking into it. Forgot to mention I already have a node/express back end. I was thinking there must be an angular way of doing this. – ng-mad Apr 11 '14 at 16:46

2 Answers2

0

One of the simplest (in my opinion) implementations of client-client communication is using WebSockets. While that does have compatibility limitations (some browsers), that can easily be overcome by using a library like socket.io. Also, it's easy to write an Angular wrapper/service over socket.io that can be shared across components of your app, or even different modules.

It's also pretty simple to write a Node backend with socket.io

This might be a good read.

Ashesh
  • 2,885
  • 4
  • 25
  • 46
  • Thank you for taking the time to answer my newbie question! It seems obvious now. Sorry I can't vote up due to reputation. – ng-mad Apr 15 '14 at 17:33
0

I would suggest you to focus on pushing stream rather than sharing it. Some how you need to push stream to second view which is changes in first view.

You may want to check this Is there some way to PUSH data from web server to browser?

Community
  • 1
  • 1
serhads
  • 452
  • 2
  • 7
  • 22