0

Im wondering if someone could please advise.

I have data coming in through a Socket.io service to a component. Trying to decide what approach is most logical?

I can either:

A. Have the parent component call the observer and Push the data to the variable via an @Input and then update it via OnChange.

B. Call the service in the component and just update the variable from the subscriber.

C. call the service in the component and update the variable in the ngDoCheck.

Just wondering which makes the most logical sense? or does it actually even matter seeing as the data updates regardless of each route?

Crash1hd
  • 615
  • 7
  • 23
  • I'd go with B unless this child component is reusable and is being used in multiple places then A – ihor.eth Jun 20 '20 at 05:38
  • Why would you go A if it is used in multiple places? – Crash1hd Jun 20 '20 at 05:39
  • to no repeat logic to get data from service in all child components especially if they are rendered in like ngFor loop cause that I guess would create multiple unnecessary socket connections .. ? – ihor.eth Jun 20 '20 at 05:41
  • If there is a single socket connection but just multiple subscriptions though would that stay with A? – Crash1hd Jun 20 '20 at 05:42

0 Answers0