使用angular 4,Node js mysql构建实时通知

时间:2018-03-22 23:13:22

标签: node.js angular websocket server socket.io

我需要使用Angular 4,Node js的实时通知示例。 我正在研究关于在前端使用Angular4和在后端使用symfony3在邻居之间共享文章的项目,在我的项目中,我使用通知通过单击“借用”按钮通知邻居他们想要借用的巫术文章

1 个答案:

答案 0 :(得分:1)

First I recommend adding angular2-toaster, it is an easy to use notification system that will run on the 'client side' (angular 4 side) that the user will see. Then you will need to setup socket.io, https://socket.io/get-started/chat/ follow the chat tutorial but instead of chat, set it up with angular2-toaster for notifications.

Now in your RESTFUL API, when a call is made (in your NodeJS backend for instance, when a user adds 'action' that relates to another user, maybe a 'neighbor' as you say) stream to socket.io the relevant information to the neighbor.

In angular 4 have a listener for socket.io from your backend and subscribe angular2-toaster notifications to it!