AngularJs enables real-time refresh of the chat list and angularjs
Yesterday, I encountered a problem in the chat list of the app. The message listener listened to a new message, but if it is already on the message list page, the message list will not be updated in time.
My idea is that in the listener method in the service layer, when a new message is received, a broadcast is sent in the root scope, tell the controller layer to obtain the latest message list.
Broadcast in service layer:
Answer broadcast at the controller layer:
RootScope is the parent level of all scopes.
Its broadcast (broadcast) and listening (on) can be used between non-overlapping controllers.
Broadcast and on of scope are used to transfer events between controllers with overlapping scopes (parent-child relationship) different from rootScope.
The above is the AngularJs introduced by xiaobian to refresh the chat list in real time. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!