I\'m trying to call a service from a particular class, but for some reason it can\'t be called, even though I am able to use it in other classes. I\'m using @Input
In my case, I imported the service as
import {MyService} from '../services/my.service'
in one place, and
import {MyService} from '../services/index'
in the other place, while index.ts contains all export statements for services in the same folder.
After I unified to the 2nd form of importing, the problem had gone.
This will happen if something wrong was provided as a provider. And it is unlikely that there may be another reason for this.
In one place it is ...shared/service/cert.service
, and in another it is ...shared/Service/cert.service
. Case matters. It depends on the environment what happens with these modules during build process, but this can cause errors, e.g. they may become duplicated and refer to different objects.
To quickly debug this, CertService
can be exposed from both files as window.CertService1
and window.CertService2
and compared in console if both are defined and equal.
Exactly the same error message ("No provider for SomeService") can be triggered by having another service with the same name in your app. So it would look like you correctly included SomeService #1 in your module, added to the providers section, but it would still throw you the error. It puzzled me until I realized that there's SomeService #2 being imported in one of my components.