'Angular library, service: Module has no exported member

I am creating an Angular library with styling, components, and services. Although, I cannot get the service I have created to successfully import into my test application, where all my components and styles are working fine.

In my test app component:

import { LocalStorageService } from 'my-library';

I am getting the error:

Module 'my-library' has no exported member 'LocalStorageService'.

Importing it into the test app:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MyModule } from 'my-library';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    MyModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Here is how I am building the service in the library:

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})

export class LocalStorageService {

   isLocalStorageSupported: boolean;

  constructor() {}

  put(name:string, item:any): boolean {
    return true;
  }
}

the module:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { MatDialogModule } from '@angular/material/dialog'
import { MatButtonModule } from '@angular/material/button'
import {LocalStorageService} from '../services/local-storage.service'


@NgModule({
  declarations: [
  ],
  imports: [
    CommonModule,
    MatDialogModule,
    BrowserAnimationsModule,
    MatButtonModule
  ],
  providers: [
    LocalStorageService
  ],
  exports: [
    LocalStorageService
  ]
})
export class MyModule { }

What do I need to do to correctly export my service from my library?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source