我有一个ApiService
,我不想与组件共享。仅在其他服务中使用。
NgModule
@NgModule({
providers: [
{ provide: 'APIUrl', useValue: window.angularConfig.APIUrl },
// ... declare secret imports like above
],
exports: [
FileService,
FolderService,
],
})
export class ServicesModule { }
私人服务
@Injectable({
providedIn: ServicesModule,
})
class ApiService {
@Inject('secret') secret!: string;
makeApiCall(url: string) { /* make HTTP call and send secret in header */}
}
公共服务
@Injectable({
providedIn: ServicesModule,
})
class PublicService {
constructor(private api: ApiService ) {}
getNames(url: string) {
return this.api.makeApiCall('url/endpoint')
}
}
此解决方案给我这样的错误:
WARNING in Circular dependency detected:
... \ services \ apis.service.ts-> ... \ services.module.ts-> ... \ public.service.ts-> ... \ apis.service.ts`