一次调用后Socket.io函数不运行

时间:2019-10-17 17:52:22

标签: node.js angular sockets socket.io

//////////////user-friends.component.ts

public addFriend(friendId){
   this.appService.addFriend(this.userId, friendId).subscribe((apiResponse)=>{
     if(apiResponse.status===200){
       this.getAllUsersList(this.userId);
       this.toastr.success(apiResponse.message);
       console.log(apiResponse);
     }
     else{
       this.toastr.error('Unable to add Friend');
       console.log(apiResponse);
     }
   })
 }

public getAllUsersList:any=(userId)=>{
   console.log("socket called");
   this.friendSocketService.userList(userId).subscribe((apiResponse)=>{
     if(apiResponse.status===200){
       console.log("hi",apiResponse.data);
       this.userList=[];
       this.userList=apiResponse.data;
     }      
     console.log(this.userList);
   })
 }

/////////////////////friendSocketService
public userList = (userId) => {

   this.socket.emit('getUsers', userId);

   return Observable.create((observer)=>{
     this.socket.on('UsersListSuccess',(data)=>{
       console.log("from userList socket "+data.data[0]);
       observer.next(data);
     }); // end of socket
   }) // end of observable

 } // end getChatMessage

////////////////////chrome console
socket called

friend-list-socket.service.ts:39 from userList socket [object Object]

user-friends.component.ts:60 hi 

client:52 [WDS] Live Reloading enabled.

user-friends.component.ts:57 socket called

user-friends.component.ts:43 {error: false, message: "Request Sent", status: 200, data: null}

当我第一次在构造函数中调用套接字时,将运行好友列表并加载该列表,但是当我尝试通过单击添加好友按钮来调用另一次时,套接字部分未运行。

请对此提供帮助。.调用了包含套接字的函数,但未以某种方式调用套接字。

0 个答案:

没有答案