我正在努力在库和使用它的应用程序中使用Firebase实例。我尝试了不同的方法,但到目前为止,我一直在尝试这种配置。
import { ModuleWithProviders, NgModule, LOCALE_ID } from "@angular/core";
import { HTTP_INTERCEPTORS, HttpClient } from "@angular/common/http";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { RouterModule } from "@angular/router";
import { CommonModule, registerLocaleData } from "@angular/common";
import localeUk from "@angular/common/locales/uk";
registerLocaleData(localeUk);
import { TranslateLoader, TranslateModule } from "@ngx-translate/core";
import { LoggingInterceptor } from "./logging.interceptor";
import { NotFoundComponent } from "./not-found/not-found.component";
import { SidebarComponent } from "./sidebar/sidebar.component";
import { AuthService } from "./auth.service";
import { DatesService } from "./dates.service";
import { LocalizationService } from "./localization.service";
import { CalculationsService } from "./calculations/calculations.service";
import { NavService } from "./nav.service";
import { SigninComponent } from "./auth/signin/signin.component";
import { ChangePassComponent } from "./auth/change-pass/change-pass.component";
import { AntiAuthGuard } from "./auth/antiAuth.guard";
import {
AuthGuard,
AutoAuthRoleCredential,
AUTO_AUTH_ROLE_CREDENTIALS
} from "./auth.guard";
import { FormsModule } from "@angular/forms";
import { HttpLoaderFactory } from "./HttpLoaderFactory";
import { UIModule } from "./ui/ui.module";
import { AngularFireModule, FirebaseAppConfig } from "@angular/fire";
import { AngularFireAuth } from "@angular/fire/auth";
import { AngularFirestore } from "@angular/fire/firestore";
export interface TCoreModuleConfig {
autoAuthRoleCredentials: AutoAuthRoleCredential[];
firebaseConfig: FirebaseAppConfig;
}
// @dynamic
@NgModule({})
export class TCoreModule {
static forRoot(config: TCoreModuleConfig): ModuleWithProviders {
@NgModule({
imports: [
CommonModule,
RouterModule,
FormsModule,
AngularFireModule.initializeApp(config.firebaseConfig),
CommonModule,
RouterModule,
FormsModule,
NgbModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
providers: [AngularFirestore, AngularFireAuth],
declarations: [
NotFoundComponent,
SidebarComponent,
SigninComponent,
ChangePassComponent
],
exports: [
SidebarComponent,
NotFoundComponent,
SigninComponent,
ChangePassComponent
]
})
class TCoreInnerModule {}
return {
ngModule: TCoreInnerModule,
providers: [
AuthService,
CalculationsService,
DatesService,
LocalizationService,
NavService,
AntiAuthGuard,
AuthGuard,
{
provide: AUTO_AUTH_ROLE_CREDENTIALS,
useValue: config.autoAuthRoleCredentials
},
{
provide: HTTP_INTERCEPTORS,
useClass: LoggingInterceptor,
multi: true
},
{
provide: LOCALE_ID,
deps: [LocalizationService],
useFactory: localizationService =>
localizationService.getLocale()
}
]
};
}
static forChild(config: TCoreModuleConfig): ModuleWithProviders {
return this.forRoot(config);
}
}
当我尝试使用这样的配置进行构建时,会出现这种错误:
Cannot determine the module for class SidebarComponent in /Users/yosyf/Code/TA/t-plugins/projects/t-core/src/lib/sidebar/sidebar.component.ts! Add SidebarComponent to the NgModule to fix it.
所有其他组件都一样。我尝试了不同的方法,方法是从顶层模块中导出组件,而不仅是内部模块,也无法导出。