我正在将ASP.NET Boilerplate与Angular(6)一起使用。我想启用服务器端渲染,主要是为了在社交媒体上启用共享。服务器应用程序的构建进展顺利,我可以为该应用程序提供服务,但是在配置的端口(localhost:42000)上打开它时,出现“参考错误:未定义abp”。 在此之前,我遇到了诸如“未定义窗口”和“未定义位置”之类的错误,并且通过模拟server.ts文件中的窗口,文档,导航器和位置对象来消除这些错误。 我不是Angular专家,所以将不胜感激。
此问题的第一次出现是在root.module.ts中的appInitializerFactory函数中。 这是我的root.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule, Injector, APP_INITIALIZER, LOCALE_ID } from '@angular/core';
import { AbpModule } from '@abp/abp.module';
import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { SharedModule } from '@shared/shared.module';
import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module';
import { RootRoutingModule } from './root-routing.module';
import { AppConsts } from '@shared/AppConsts';
import { AppSessionService } from '@shared/session/app-session.service';
import { API_BASE_URL } from '@shared/service-proxies/service-proxies';
import { RootComponent } from './root.component';
import { AppPreBootstrap } from './AppPreBootstrap';
import { ModalModule } from 'ngx-bootstrap';
export function appInitializerFactory(injector: Injector) {
return () => {
abp.ui.setBusy();
return new Promise<boolean>((resolve, reject) => {
AppPreBootstrap.run(() => {
abp.event.trigger('abp.dynamicScriptsInitialized');
var appSessionService: AppSessionService = injector.get(AppSessionService);
appSessionService.init().then(
(result) => {
abp.ui.clearBusy();
resolve(result);
},
(err) => {
abp.ui.clearBusy();
reject(err);
}
);
});
});
}
}
export function getRemoteServiceBaseUrl(): string {
return AppConsts.remoteServiceBaseUrl;
}
export function getCurrentLanguage(): string {
return abp.localization.currentLanguage.name;
}
@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
BrowserAnimationsModule,
SharedModule.forRoot(),
ModalModule.forRoot(),
AbpModule,
ServiceProxyModule,
RootRoutingModule,
],
declarations: [
RootComponent
],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true },
{ provide: API_BASE_URL, useFactory: getRemoteServiceBaseUrl },
{
provide: APP_INITIALIZER,
useFactory: appInitializerFactory,
deps: [Injector],
multi: true
},
{
provide: LOCALE_ID,
useFactory: getCurrentLanguage
}
],
bootstrap: [RootComponent]
})
export class RootModule {
}