Good or bad to provide services per component angular 4? -
actually, have 2 questions angular 4 best practice.
- i have service named
remoteservice
, responsible xhr calls. want catch component instance, using service, inremoteservice
. guess, better provide service per component level. because don't want every methods of service take component instance parameter. but, or bad provide service per component?. way:remoteservice
used in hundreds of components. - i'm trying follow style guide of angular. should place
remoteservice
?. shared feature module or core feature module?. it's purpose seemsexceptionservice
,loggerservice
. not singleton service explained above. may depends on answer of question 1.
so answer both questions - remoteservice
idea. call mine apiservice
.
this idea several reasons -
- all http calls out of 1 file allows single endpoint external requests. it's more organized having calls come out of individual component-level services
- you have more control on calls. meaning, if needed put logic between call component, , actual http call (example - authentication check) - don't want run around app changing everywhere - instead have local function wraps http request, , provides logic.
in terms of put - john papa's style guide suggests putting file in shared
folder: https://johnpapa.net/angular-2-styles/
Comments
Post a Comment