How can I update the $scope in AngularJS when a server sided update occurs?

Arithran

Background

  1. I am trying to make a single page real-time application that uses a PHP , MYSQL back end and AngularJS frontend

  2. My back end is using CakePHP framework which serves a JSON API and the front uses ngResource in AngularJS to access this API.

  3. I have got 'Ratchet WebSockets for PHP' working, which can trigger a response to the browser via websockets when something updates in the back end.


My Incomplete Solutions

Solution 1: Use the response via the websocket to update the AngularJS $scope object through some kind of $scope.model.push(websocket.data) method?

Solution 2: Use the response via the websocket to trigger Refresh on the ngResource which would refresh the $scope object completely?


Question

Are my solutions viable? and how could I achieve it ?

vtortola

You just need to read events from the WS and populate them using $emit and $broadcast, then your controllers can subscribe to whichever events are relevant to them.

Take a look at:

angular websocket factory

AngularJS and WebSockets beyond

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS: How can I update the $scope property

From Dev

How do I update an angularjs page after a scope update?

From Dev

How can I update protobuf file for client when server changed

From Dev

How to update UI using angularJs when scope value changes?

From Dev

How can I pass this callback in Angular and update $scope?

From Dev

How to update HP BIOS when I can not find the update

From Dev

AngularJS how to dynamically update part of scope with variable

From Dev

How to update $scope outside the modal bootstrap in AngularJS?

From Dev

How to softly update $scope and template using Angularjs?

From Dev

How to update $scope variable value in AngularJs

From Dev

AngularJS/jQuery - Update Scope

From Dev

How can I prevent log growth in SQL Server when update millions of records, not insert

From Dev

A "failed to fetch" error occurs when apt-get update is run. How do I fix this?

From Dev

A "failed to fetch" error occurs when apt-get update is run. How do I fix this?

From Dev

How can I update the model in parent scope from inside the child scope?

From Dev

How can I update a variable from an AngularJS view?

From Dev

How can I update the AngularJS/SailsJS/MongoDB Todo Application?

From Dev

How can I update the text of a JButton when I click on it?

From Dev

How to bind and automatically update view when $scope is updated in 2 different controllers in Angularjs

From Dev

How can I validate data before insert/update with SQL Server?

From Java

How can I do an UPDATE statement with JOIN in SQL Server?

From Dev

AngularJS view doesn't update when assigning a $http response to $scope

From Dev

AngularJS Controller to update $scope automatically when backend data changes

From Java

Update parent scope variable in AngularJS

From Dev

AngularJS animate div on scope update

From Dev

How can I ask a JMS server to resend the message when an exception occurs in a JMS listener defined with the @JmsListener annotation?

From Java

How can I update a secret on Kubernetes when it is generated from a file?

From Dev

How can I get a textbox to update when a checkbox is checked?

From Dev

How can I automatically update a filter when my analysis is opened?

Related Related

  1. 1

    AngularJS: How can I update the $scope property

  2. 2

    How do I update an angularjs page after a scope update?

  3. 3

    How can I update protobuf file for client when server changed

  4. 4

    How to update UI using angularJs when scope value changes?

  5. 5

    How can I pass this callback in Angular and update $scope?

  6. 6

    How to update HP BIOS when I can not find the update

  7. 7

    AngularJS how to dynamically update part of scope with variable

  8. 8

    How to update $scope outside the modal bootstrap in AngularJS?

  9. 9

    How to softly update $scope and template using Angularjs?

  10. 10

    How to update $scope variable value in AngularJs

  11. 11

    AngularJS/jQuery - Update Scope

  12. 12

    How can I prevent log growth in SQL Server when update millions of records, not insert

  13. 13

    A "failed to fetch" error occurs when apt-get update is run. How do I fix this?

  14. 14

    A "failed to fetch" error occurs when apt-get update is run. How do I fix this?

  15. 15

    How can I update the model in parent scope from inside the child scope?

  16. 16

    How can I update a variable from an AngularJS view?

  17. 17

    How can I update the AngularJS/SailsJS/MongoDB Todo Application?

  18. 18

    How can I update the text of a JButton when I click on it?

  19. 19

    How to bind and automatically update view when $scope is updated in 2 different controllers in Angularjs

  20. 20

    How can I validate data before insert/update with SQL Server?

  21. 21

    How can I do an UPDATE statement with JOIN in SQL Server?

  22. 22

    AngularJS view doesn't update when assigning a $http response to $scope

  23. 23

    AngularJS Controller to update $scope automatically when backend data changes

  24. 24

    Update parent scope variable in AngularJS

  25. 25

    AngularJS animate div on scope update

  26. 26

    How can I ask a JMS server to resend the message when an exception occurs in a JMS listener defined with the @JmsListener annotation?

  27. 27

    How can I update a secret on Kubernetes when it is generated from a file?

  28. 28

    How can I get a textbox to update when a checkbox is checked?

  29. 29

    How can I automatically update a filter when my analysis is opened?

HotTag

Archive