问题
I am facing an issue while ng build --prod:
Function calls are not supported in decorators but 'Ui' was called in 'initialState'
export const initialState: AppState = {
userAisles: null,
userItems: null,
userLists: null,
userShops: null,
ui: new Ui(),
config: new Config(),
};
and my Ui class:
export class Ui {
loading: false;
itemsOrder = 'name';
itemsOrderSense = 'ASC';
listsOrder = 'date';
listsOrderSense = 'ASC';
listsConsultOrder = 'name';
listsConsultOrderSense = 'ASC';
history: string = null;
resolved = false;
constructor(values: Object = {}) {
return Object.assign(this, values);
}
}
If I hardcode the Ui class in initialState, it works and then complains about Config class, so the problem is there. I don't find any solution to get rid of the compiling error message.
Here's my config:
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"@ngrx/effects": "^6.1.0",
"@ngrx/router-store": "^6.1.0",
"@ngrx/store": "^6.1.0",
"@ngrx/store-devtools": "^6.1.0",
"angular-hammer": "^2.2.0",
"bootstrap": "4.1.3",
"core-js": "^2.5.4",
"font-awesome": "~4.7.0",
"moment": "^2.20.1",
"ng2-dragula": "^2.0.2",
"ngx-facebook": "^2.4.0",
"primeng": "^6.1.2",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
"zone.js": "^0.8.26"
Thanks for your help
回答1:
can you use a factory method?
instead of calling new Ui()
or new Config()
use a function that returns a new Ui or a new Config object like this:
export const uiFactory(){
return new Ui();
}
export const configFactory(){
return new Config();
}
export const initialState: AppState = {
userAisles: null,
userItems: null,
userLists: null,
userShops: null,
ui: uiFactory,
config: configFactory
};
or will they not be called?
or just do
const config = new Config();
{.... config: config .....}
cause initialState will be binded only once.
来源:https://stackoverflow.com/questions/52098499/function-calls-are-not-supported-in-decorators