55


I am trying to export an Service from one of my modules but i only get the following error:

ERROR Error: Uncaught (in promise): 
Error: Can't export value ConfirmDialogService from SharedModule as it was neither declared nor imported!

My Module is the following:

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 {}

The files do exist and are referenced correctly in TS but when running the app the error appears.

Code Spirit
  • 3,992
  • 4
  • 23
  • 34
  • this question was marked duplicate but couldn't able to find other article or its reference here which provides its solution. – Mukesh Rathore Oct 17 '19 at 17:22

1 Answers1

107

You don't need to list services in exports, and you can only list components, directives, and pipes. For services, providers is relevant, but otherwise a TypeScript import is enough.

Pezetter
  • 2,783
  • 2
  • 22
  • 40
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567