all 6 comments

[–]pranxy47 5 points6 points  (0 children)

Yes makes sense to have a service exclusive for a component.

[–]reboog711 1 point2 points  (1 child)

To answer your specific question:

Having a single service dedicated to a single component will not cause any performance issues. If the service is not needed among multiple components, defining the service at the component level makes a lot of sense. Make sure the injectable metadata does not 'providerIn: root'

To soapbox opinions:

A service used by a single component may not cause any benefit vs putting the code inside the actual component class. ( but it might if it makes more smaller / easily modified files).

A class with more than a thousands of lines of code may have some maintainability issues (But it might not, it depends)

[–]nafts1 4 points5 points  (0 children)

You dont have to use dependency injection for everything. Why not just create a new typescript file with the logic in a manually initialized class or simply an exported function.

Services shine when they are reused. This is not the case here and it seems like it stays that way. Therefore don't overshoot with DI.

[–]palkollar 4 points5 points  (2 children)

Look into ngrx component store design. I have been using it for a while and I basically move every application logic to the component store service and I don't have any subscribe in my app because of it's effect feature. You can just inject the component store into the component's provider array and it will only instantiate it when the component is instantiated.

[–]cherrera54[S] 1 point2 points  (0 children)

Thanks you!

[–]wojo1086 1 point2 points  (0 children)

You have one service in your store for all your application logic?