Good or bad to provide services per component angular 4? -


actually, have 2 questions angular 4 best practice.

  1. i have service named remoteservice, responsible xhr calls. want catch component instance, using service, in remoteservice. 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.
  2. i'm trying follow style guide of angular. should place remoteservice?. shared feature module or core feature module?. it's purpose seems exceptionservice , 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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -