#Providing a service in a service

1 messages · Page 1 of 1 (latest)

wicked harbor
#

Can you show the code where you provide the multiple services in the parent

lapis glade
#

I just provide it normally
@Component({
selector: 'parent-component',
template: '<name-component></name-component>,
providers: [ MainStoreService, SubComponent1Service, SubComponent2Service ...]
})

wicked harbor
#

instead of providing it here, you can provide them in the Module where this component is declared

#

if the component is standalone you can provide them in the routing for those components

#

I suspect if you put sub services inside the main one you will still get an exception that they are not being provided anywhere so this is not the fix

#

or just declare them as providedIn: 'root' so that you never need to provide them anywhere

lapis glade
#

i cannot provide it in the module since I need a different instance for each instance of name-component

lapis glade