Websocket in Angular 4 and RxJS confusion

前端 未结 1 1548
我在风中等你
我在风中等你 2021-02-01 09:29

I am trying to learn RxJS with websockets and Angular 4, and found a good example here. I\'m hoping someone can help explain the example as a few things are confusing.

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 10:18

    1. Reuseability
    2. so you can unsubscribe from observable which in turn closes the connection
    3. in the example you gave it would probably be something like (when you have a instance of chatService)

      let sub = chatService.messages.subscribe(()=>{ 
      // do your stuff 
      });
      
      // some where in your code
      sub.unsubscribe() // this will close the connection
      
    4. already answered in 3

    0 讨论(0)
提交回复
热议问题