我试图从我的一个模块导出服务,但我只得到以下错误:
ERROR Error: Uncaught (in promise):
Error: Can't export value ConfirmDialogService from SharedModule as it was neither declared nor imported!
我的模块如下:
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { FormsModule } from "@angular/forms";
import { RouterModule } from "@angular/router";
import { MaterialModule } from "@angular/material";
import { ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';
import { ConfirmDialogService } from './confirm-dialog/confirm-dialog.service';
@NgModule({
imports: [
RouterModule,
CommonModule,
MaterialModule,
FormsModule
],
providers: [
ConfirmDialogService
],
declarations: [
ConfirmDialogComponent
],
exports: [
ConfirmDialogComponent
ConfirmDialogService
]
})
export class SharedModule {}
文件确实存在并在TS中正确引用,但在运行应用程序时会出现错误。
答案 0 :(得分:69)
您不需要在exports
中列出服务,您只能列出组件,指令和管道。对于服务,providers
是相关的,否则TypeScript导入就足够了。