Angular2: Unsubscribe from http observable in Service

后端 未结 3 1367
孤街浪徒
孤街浪徒 2020-12-05 01:56

What is the best practice to unsubscribe within a Angular2 service from a http subscription?

Currently I do this but I\'m not sure if this will be the best way.

3条回答
  •  抹茶落季
    2020-12-05 02:46

    You don't need to unsubscribe from observable created by Http or HttpClient because it is finite observable (value will be emitted only once and complete will be called).

    However, you CAN unsubscribe from the observable created by HttpClient to cancel the request. It mean you are no longer interested in data returned by the request.

提交回复
热议问题