DelonModule
是第三个文件。它有许多帮助开发的功能,例如ACL
auth
等。
重点是,我几天前正好打包它。但是当我输入命令ERROR in Error during template compile of 'AppModule' Function calls are not supported in decorators but 'DelonModule' was called.
时它以某种方式报告错误ng build
。
delon.module.ts
代码如下(core code
)
@NgModule({
imports: [
NgZorroAntdModule.forRoot(),
NgZorroAntdExtraModule.forRoot(),
// theme
AlainThemeModule.forRoot(),
// abc
AdErrorCollectModule.forRoot(), AdFooterToolbarModule.forRoot(), AdSidebarNavModule.forRoot(), AdDownFileModule.forRoot(), AdImageModule.forRoot(),
AdAvatarListModule.forRoot(), AdDescListModule.forRoot(), AdEllipsisModule.forRoot(), AdExceptionModule.forRoot(), AdExceptionModule.forRoot(),
AdNoticeIconModule.forRoot(), AdNumberInfoModule.forRoot(), AdProHeaderModule.forRoot(), AdResultModule.forRoot(), AdStandardFormRowModule.forRoot(),
AdTagSelectModule.forRoot(), AdTrendModule.forRoot(), AdUtilsModule.forRoot(), AdChartsModule.forRoot(), AdCountDownModule.forRoot(), AdSimpleTableModule.forRoot(),
AdReuseTabModule.forRoot(),
AdFullContentModule.forRoot(), AdXlsxModule.forRoot(), AdZipModule.forRoot(),
// auth
AlainAuthModule.forRoot({
// 受限于 https://github.com/cipchk/ng-alain/issues/246, 只支持字符串形式
// ignores: [ `\\/login`, `assets\\/` ],
login_url: `/passport/login`
}),
// acl
AlainACLModule.forRoot(),
// cache
DelonCacheModule.forRoot()
]
})
export class DelonModule {
constructor(@Optional() @SkipSelf() parentModule: DelonModule) {
throwIfAlreadyLoaded(parentModule, 'DelonModule');
}
static forRoot(): ModuleWithProviders {
const _NZ_MESSAGE_CONFIG = {
nzDuration: 1500,
nzMaxStack: 1,
nzPauseOnHover: true,
nzAnimate: true
};
return {
ngModule: DelonModule,
providers: [
{ provide: NZ_MESSAGE_CONFIG, useValue: _NZ_MESSAGE_CONFIG },
{ provide: DA_STORE_TOKEN, useClass: SessionStorageStore }
// TIPS:@delon/abc 有大量的全局配置信息,例如设置所有 `simple-table` 的页码默认为 `20` 行
// { provide: SimpleTableConfig, useFactory: simpleTableConfig }
]
};
}
}
app.module.ts
代码如下
import { NgModule, LOCALE_ID, APP_INITIALIZER, Injector } from '@angular/core';
import { HttpClient, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DelonModule } from './delon.module';
import { CoreModule } from './core/core.module';
import { SharedModule } from './shared/shared.module';
import { AppComponent } from './app.component';
import { RoutesModule } from './routes/routes.module';
import { LayoutModule } from './layout/layout.module';
import { StartupService } from '@core/startup/startup.service';
import { DefaultInterceptor } from '@core/net/default.interceptor';
import { SimpleInterceptor } from '@delon/auth';
import { DA_STORE_TOKEN } from '@delon/auth';
// ngx-cookie
import { CookieModule } from 'ngx-cookie';
// angular i18n
import { registerLocaleData, DatePipe } from '@angular/common';
import localeZhHans from '@angular/common/locales/zh-Hans';
registerLocaleData(localeZhHans);
// i18n
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ALAIN_I18N_TOKEN } from '@delon/theme';
import { I18NService } from '@core/i18n/i18n.service';
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, `assets/i18n/`, '.json');
}
// JSON-Schema form
import { JsonSchemaModule } from '@shared/json-schema/json-schema.module';
export function StartupServiceFactory(startupService: StartupService): Function {
return () => startupService.load();
}
// import { CookieModule, CookieService } from 'ngx-cookie';
import { ReuseTabService } from '@delon/abc/reuse-tab/reuse-tab.service';
import { Logger, Options } from 'angular2-logger/core';
import { isDevMode } from '@angular/core';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
DelonModule.forRoot(),
CoreModule,
SharedModule,
LayoutModule,
JsonSchemaModule,
RoutesModule,
// ngx-cookie
CookieModule.forRoot(),
// i18n
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
providers: [/*
Logger,
{ provide: Options, useValue: { level: environment.logger, store: true } }, */
Logger,
Options,
DatePipe,
{ provide: LOCALE_ID, useValue: 'zh-Hans' },
// { provide: DA_STORE_TOKEN, useClass: CookieStorage, multi: false }, // 在此处注入后, 就可以通过DA_SERVICE_TOKEN获取被注入的类型.
{ provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true },
{ provide: ALAIN_I18N_TOKEN, useClass: I18NService, multi: false },
StartupService,
ReuseTabService,
{
provide: APP_INITIALIZER,
useFactory: StartupServiceFactory,
deps: [StartupService],
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(private logger: Logger) {
this.logger.level = environment.logger.Level;
}
}
如何找出这个问题?
答案 0 :(得分:1)
这只是因为你正在执行forRoot中的一些代码,你应该删除:
4
使用内联声明重新编码:
const _NZ_MESSAGE_CONFIG = {
nzDuration: 1500,
nzMaxStack: 1,
nzPauseOnHover: true,
nzAnimate: true
};