模块内的Angular 6访问服务给出错误“模块没有导出成员”

时间:2018-08-20 16:59:39

标签: angular typescript angular6

我建立了一个库,在该库中我导出了以下一些模块和服务

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是已发布库的名称。我正在如下另一个应用程序中使用此库:

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

在构建库时如何访问已导出的各种服务?

当我尝试import {BaMenuService} from 'theme-lib';时,由于“ Lib没有作为BaMenuService的导出成员”,它给了我错误。

这是theme-lib.d.ts的外观,我确实看到了导出的各种模块和服务。不知道为什么会收到“库没有导出成员错误”的信息。

/**
 * 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';

我想念什么?有指针吗?感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您需要导出应该可以从外部访问的所有内容。这必须在./public_api.ts内部完成,然后看起来应该像这样:

export * from './lib/theme/services';

否则,该服务将仅在您在my-lib.d.ts中看到的令牌下可用