Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant export service from module 'it was neither declared nor imported' [duplicate]


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.

like image 512
Code Spirit Avatar asked May 23 '17 11:05

Code Spirit


1 Answers

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.

like image 163
Günter Zöchbauer Avatar answered Oct 15 '22 10:10

Günter Zöchbauer