0

Angular has two ways data binding which is cool, so I just wonder if it could be sync in Server-Client binding? For example, usually we would request data by $http

$http.get(apiURL)
    .then(function(rsp){
      console.log('getRsp', rsp);
    });

I hope it could send request automatically once server side (inside database for example) changes.

In tranditionally, we can use timeout, but it is kind old way, and watsting resource. What if we can listen the server change? But how?!

4

1 Answer 1

1

You can achiece this by using socket.io. Both on server and client side. By using timeout all of the clients will repeatedly keep on calling the server even if there is no update. With sockets you can keep a channel open between server and client. The server will only notify the client whenever there is a change in the data.

You can find a lot tutorials for sockets on the internet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.