gpt4 book ai didi

angular - 装饰器不支持函数调用

转载 作者:太空狗 更新时间:2023-10-29 17:40:11 28 4
gpt4 key购买 nike

我在 ng build --prod 时遇到问题:

装饰器不支持函数调用,但在“initialState”中调用了“Ui”

export const initialState: AppState = {
userAisles: null,
userItems: null,
userLists: null,
userShops: null,
ui: new Ui(),
config: new Config(),
};

和我的 Ui 类:

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);
}
}

如果我在 initialState 中硬编码 Ui 类,它可以工作,然后提示 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"

谢谢你的帮助

最佳答案

可以使用工厂方法吗?而不是调用 new Ui()new Config() 使用返回新 Ui 或新 Config 对象的函数,如下所示:

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
};

或者他们不会被调用?

或者只是做

const config = new Config();
{.... config: config .....}

因为 initialState 只会被绑定(bind)一次。

关于angular - 装饰器不支持函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52098499/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com