Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Angular DI question, how to inject a service in service

I can successfully inject TestService into CertService When I use CertModule provider, such as:

@NgModule({
  declarations: [
  ],
  imports: [
  ],
  providers: [
   CertService,
   TestService
  ],
  exports: [CertComponent],
  bootstrap: [CertComponent]
})

But I want to limit the scope of TestService within CertComponent. So my purpose is to move the provider from CertModule to CertComponent. such as:

@Component({
  selector: 'cert-component',
  templateUrl: 'cert.component.html',
  styleUrls: ['cert.component.scss'],
  providers: [
    TestService
  ]
})

But I find If I do this, will face a problem:

taticInjectorError(AppModule)[CertService -> TestService]:

Comments