Reputation: 2620
I have built a library where I am exporting few modules and services as below
export class ThemeLibModule {
static forRoot(): ModuleWithProviders {
return <ModuleWithProviders>{
ngModule: ThemeLibModule,
providers: [
BaThemeConfigProvider,
BaThemeConfig,
GlobalState,
...NGA_VALIDATORS,
...NGA_SERVICES,
],
};
}
const NGA_SERVICES = [BaImageLoaderService,BaThemePreloader,BaThemeSpinner,BaMenuService,];
theme-lib
is name of the published Library. I am using this library in another application as below :
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import {ThemeLibModule} from 'theme-lib';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ThemeLibModule.forRoot(),
HttpClientModule,
HttpModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
How do I access various services that I have exported while building the library ?
When I try import {BaMenuService} from 'theme-lib';
it gives me error as "Lib has no export member as BaMenuService".
This is how theme-lib.d.ts looks and I do see various modules and services exported. Not sure why am I getting "Lib has not export member error".
/**
* Generated bundle index. Do not edit.
*/
export * from './public_api';
export { AppTranslationModule as ɵbn, createTranslateLoader as ɵbm } from './lib/app.translation.module';
export { BaThemeConfigProvider as ɵl } from './lib/theme';
export { AutoCompleteComponent as ɵbk, BaBackTop as ɵm, BaBreadCrumb as ɵba, BaCancelButtonComponent as ɵbd, BaCard as ɵn, BaChartistChart as ɵo, BaCheckbox as ɵp, BaClearButtonComponent as ɵbg, BaContentTop as ɵq, BaFileUploader as ɵz, BaFullCalendar as ɵr, BaMenu as ɵt, BaMenuItem as ɵs, BaMsgCenter as ɵu, BaMultiCheckbox as ɵv, BaPage as ɵbc, BaPageTop as ɵw, BaPane as ɵbb, BaPictureUploader as ɵx, BaSaveButtonComponent as ɵbe, BaSearchButtonComponent as ɵbh, BaSidebar as ɵy, BaSubmitButtonComponent as ɵbf, BaToolBarButtonComponent as ɵbi, BaToolBarDropdownButtonComponent as ɵbj } from './lib/theme/components';
export { BaCardBlur as ɵj } from './lib/theme/components/baCard/baCardBlur.directive';
export { BaCardBlurHelper as ɵk } from './lib/theme/components/baCard/baCardBlurHelper.service';
export { BaScrollPosition as ɵg, BaSlimScroll as ɵh, BaThemeRun as ɵi } from './lib/theme/directives';
export { GlobalState as ɵbq } from './lib/theme/global.state';
export { BaAppPicturePipe as ɵa, BaKameleonPicturePipe as ɵb, BaProfilePicturePipe as ɵc, FilterPipe as ɵd, MLPCurrencyPipe as ɵf, UTCDatePipe as ɵe } from './lib/theme/pipes';
export { SaveClosePopupComponent as ɵbl } from './lib/theme/popups';
export { BaImageLoaderService as ɵbt, BaMenuService as ɵbw, BaThemePreloader as ɵbu, BaThemeSpinner as ɵbv } from './lib/theme/services';
export { BaThemeConfig as ɵbp } from './lib/theme/theme.config';
export { BaThemeConfigProvider as ɵbo } from './lib/theme/theme.configProvider';
export { EmailValidator as ɵbr, EqualPasswordsValidator as ɵbs } from './lib/theme/validators';
What am I missing? Any pointer? Thanks for helping!
Upvotes: 2
Views: 1103
Reputation: 389
You need to export everything which should be accessible from the outside-world. This has to be done inside the ./public_api.ts
, which should look then look something like this:
export * from './lib/theme/services';
Otherwise, the Service will be available only under the tokens you can see in your my-lib.d.ts
Upvotes: 3