Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - What is a DI error?

Tags:

angular

I'm having an error when I import a service, but I have no idea why

import { CDService } from "../../services/definition";

constructor(
    private toastyCommunicationService: ToastyCommunicationService,
    private CDService : CDService,
    private SharedService: SharedService,
    private DatePipe: DatePipe
) { }

I have made my service litteraly empty because I was so frustrated with the error and not knowing what was causing it.

export class CDService {

}

Now I receive the error

EXCEPTION: Uncaught (in promise): Error: DI Error
Error: DI Error

I have 2 questions:

1) What the hell is a DI error?

2) How can I solve this error?

like image 619
Nicolas Avatar asked May 28 '26 02:05

Nicolas


1 Answers

It is dependency injection error. I think you are missing @Injectable() decorator:

@Injectable() // this line
export class CDService {

} 

Edit:

Have you added CDService into NgModule?

like image 69
Igor Janković Avatar answered Jun 02 '26 02:06

Igor Janković