问题描述
我正在从Angular应用程序中构建PWA,运行 ng build --prod
时出现以下错误:
I am building a PWA from my Angular app and I am getting the following error when I run ng build --prod
:
ERROR in app\app.module.ts(108,64): Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'Environment' was called in 'environment'
'environment' calls 'Environment'.
但是,这没有任何意义,因为我在类中添加了 export
,如您所见:
However, it makes no sense because I added export
to the class as you can see here:
environment.prod.ts
import { BaseEnvironment } from './base-environment';
import { ProspectBuilderModel } from '../app/models/prospect';
export class Environment extends BaseEnvironment {
production: boolean = true;
prospectBuilderModel: ProspectBuilderModel = {
buildQuote: false,
buildAcknowledge: false,
buildOrganizationInfo: false,
buildFinancialInfo: false,
buildTradeInfo: false,
buildPermissiblePurpose: false,
buildUserSetup: false,
buildPackageSelection: false,
buildPaymentOptions: false,
buildOrderOptions: false,
buildVerifyOrganizationInfo: false,
buildDocusignAuthorization: false,
buildDocusignContract: false
};
}
export const environment = new Environment();
基本环境.ts
import { ProspectBuilderModel } from '../app/models/prospect';
export abstract class BaseEnvironment {
abstract production: boolean;
abstract prospectBuilderModel: ProspectBuilderModel;
}
app.module.ts
...
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
MultiselectDropdownModule,
ReactiveFormsModule,
HttpModule,
ToastrModule.forRoot(),
BrowserAnimationsModule,
NgxMyDatePickerModule.forRoot(),
PopoverModule.forRoot(),
ModalModule.forRoot(),
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
],
providers: [
...
有人知道我可以解决此错误吗?
Does anyone know what I can do to resolve this error?
推荐答案
下面是我最终想出的解决方案的代码.希望这对曾经遇到此类问题的人有所帮助.本质上,我只是修改了我的环境文件,所以它没有创建Environment类的实例.我猜想Angular不太可能实例化
Below is the code for the solution I finally came up with. Hope this help someone that ever runs into this type of issue. Essentially, I just modified my environment file so that it did not create an instance of the Environment class. I guess Angular no likey the instantiation:
export const environment = {
production: true,
prospectBuilderModel: {
buildQuote: false,
buildAcknowledge: false,
buildOrganizationInfo: false,
buildFinancialInfo: false,
buildTradeInfo: false,
buildPermissiblePurpose: false,
buildUserSetup: false,
buildPackageSelection: false,
buildPaymentOptions: false,
buildOrderOptions: false,
buildVerifyOrganizationInfo: false,
buildDocusignAuthorization: false,
buildDocusignContract: false
}
}
这篇关于Angular 5:装饰器中不支持函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!