How to fix this error "Uncaught (in promise): Error: StaticInjectorError(AppModule)" in Angular 7

82 views
Skip to first unread message

Jenny

unread,
Dec 3, 2018, 8:54:12 AM12/3/18
to Angular and AngularJS discussion
Hi,

How to fix this error in Angular 7 occurs when try to retrieve data from web apis?

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[AgentcategorylistingComponent -> ApiService]: 
  StaticInjectorError(Platform: core)[AgentcategorylistingComponent -> ApiService]: 
    NullInjectorError: No provider for ApiService!
Error: StaticInjectorError(AppModule)[AgentcategorylistingComponent -> ApiService]: 
  StaticInjectorError(Platform: core)[AgentcategorylistingComponent -> ApiService]: 
    NullInjectorError: No provider for ApiService!

AgentcategorylistingComponent >> is a Component
ApiService  >> is a Service

Arnaud Deman

unread,
Dec 3, 2018, 9:27:01 AM12/3/18
to Angular and AngularJS discussion
Hi Jenny,

I think you need to specify how your service is provided: see the providers section of the angular docs.

For instance, to make your service accessible from anywhere in your application you could add this in @Injectable :

@Injectable({
providedIn: 'root'
})

export class APIService

Regards,
Arnaud.

Jenny

unread,
Dec 3, 2018, 9:53:45 AM12/3/18
to Angular and AngularJS discussion
Hi Arnaud,

Thanks for your great help. It is working. Thanks a lot.

Regards,
Jenny
Reply all
Reply to author
Forward
0 new messages