angular - 模块中的 Angular 6 访问服务给出错误“模块没有导出成员”
问题描述
我已经建立了一个库,我在其中导出了几个模块和服务,如下所示
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 的外观,我确实看到了各种模块和服务的导出。不知道为什么我会收到“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';
我错过了什么?任何指针?感谢您的帮助!
解决方案
您需要导出应该可以从外部世界访问的所有内容。这必须在 内部完成./public_api.ts
,它应该看起来像这样:
export * from './lib/theme/services';
否则,该服务将仅在您可以在您的my-lib.d.ts
推荐阅读
- python - 模型中 django dateTime 的正确格式是什么?
- react-native - VsCode Intellisense 反应原生不起作用
- c# - 如何将组件的大小链接到窗口大小?
- swift - 如何快速为 UIView 扩展方法添加 Gecture
- laravel - 无法从外部 URL 显示 PDF
- angularjs - 类型 IHttpPromiseCallbackArg<{}> 不可分配给类型“字符串”
- c# - ref 列表未在命令类之外修改
- arrays - 在 datepicker 中保存 json 时区
- c# - C# - 动态加载 DLL - System.Reflection.ReflectionTypeLoadException:无法加载一种或多种请求的类型
- python - 在不使用 pd.concat 的情况下连接数百万个数据帧的更快方法