简体   繁体   English

带角的Socket.io

[英]Socket.io with angular

I am trying to implement socket.io with angular client. 我正在尝试使用angular客户端实现socket.io Lets say I am having 3 routes for my application. 可以说我有3条路线可供申请。

http://localhost:4000/#/abc http://本地主机:4000 /#/ abc

http://localhost:4000/#/abd http://本地主机:4000 /#/ abd

http://localhost:4000/#/abe http:// localhost:4000 /#/ abe

Here I am emitting file processing status from backend to client. 在这里,我从后端向客户端发出文件处理状态。 I only want to display the status to the users who are all in route 3. What is the best way to achieve this in angular? 我只想向所有在路线3中的用户显示状态。以最佳方式实现此目标的最佳方法是什么?

node.js node.js

io.emit('Test', {
        Test: "Test"
});

javascript javascript

socket.on('Test', function (data) {
    console.log(data);
});

You can check on client side your location through the $location service. 您可以通过$location服务在客户端检查您的位置。

So just do 所以做

socket.on('Test', function (data) {
    if ( $location.path().indexOf('/abe') != -1)
    {
           // display status
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM