#Service injection error in standard components

38 messages · Page 1 of 1 (latest)

last sequoia
#

Why do I get an error if I have tested the service and have root? If I add it in the app component in providers it works

ionic verge
#

@Injectable({providedIn: 'root'})
export class LogUpdateService {

#

then in the component either logupdateservice = inject(LogUpdateService)
or
constructor(private logupdateservice: LogUpdateService) {}

last sequoia
#

Yes, I have the root provider in all the services but I don't know what happens that it doesn't take it

#

And the services that belong to library modules have the module imported

ionic verge
#

It should work. maybe clear the cache and restart the dev server. I think it is in .angular/cache

#

It looks like the service has a bunch of injected services as well. You could be running into a situation where the service hasn't been created yet.

last sequoia
#

Ok, I'll try it although the project was created recently, I was very surprised

last sequoia
#

Well, that hasn't been resolved... I still have the same problem.

ionic verge
#

is one of the services overridden by {provide: myservice, useclass: somethingelse} or anything like that? If one of the nested services isn't provided properly the error may not be clear.

last sequoia
#

no, none... I don't know if it has to do with how the lazy components are being imported

ionic verge
#

I'll go over some basics. There is a root injector context, then each lazy feature creates an injection context. A service provided in a route provider or component is available to it's children. Something providedin:root that is lazy loaded won't be available in the root context until loaded, ie. a service used in that lazy loaded context, but nowhere else.

What is the service, what does it inject, and how is it used?

last sequoia
#

I have import the NgModalModule in the componente number 3

ionic verge
#

the nzModalService is what?

last sequoia
#

is the Servide on a library og ngxorro

#

but I have the imported module

ionic verge
#

where are you importing the module?

#

that doesn't seem to apply

last sequoia
last sequoia
#

and what it asks me for is Utils service and it is in root mode

ionic verge
#

is the error when you open a dialog?

last sequoia
#

nop, at start project

#

it happens with all services.. hjaha

ionic verge
#

where is the utilsservice injected?

#

what version of angular?

last sequoia
#

Homecomponent

ionic verge
#

it isn't in the homecomponent constructor

last sequoia
#

yes

#

it is not in the constructor correct

#

because is provide in root...

ionic verge
#

how and where is it used?

#

provide and inject are two different things. providedIn, or in the providers array inserts it in the injection context. inject() or constructor(private myservice: MyService) injects it in a component so you can access it.

last sequoia
#

the strange thing in HomeComponent I don't use it