问题描述
我刚刚安装了NGXS v3.6,并尝试在一个简单的静态方法上使用@Selector()来通过getScheduler方法从存储中检索状态:
@State<SchedulerPageDto>({
name: 'scheduler',defaults: {} as SchedulerPageDto
})
@Injectable()
export class SchedulerState {
@Selector()
static getScheduler(state: SchedulerPageDto) {
return state;
}
@Action(SchedulerAction)
changeSchedulerEvents(context: StateContext<SchedulerPageDto>,action: SchedulerAction) {
context.setState(action.payload);
}
}
动作:
export class SchedulerAction {
static readonly type = 'Scheduler tasks and resources';
constructor(public payload: SchedulerPageDto) {}
}
这将返回错误:
ngxs-store.js:4432未捕获的错误:选择器仅适用于方法 在ngxs-store.js:4432 在__decorate(tslib.es6.js:56) 在Module ../ src / app / store / states / scheduler.state.ts(scheduler.state.ts:13) 位于 webpack_require (引导程序:79) 在Module ../ src / app / store / index.ts(index.ts:1) 位于 webpack_require (引导程序:79) 在Module ../ src / app / app.module.ts(app.component.ts:16) 位于 webpack_require (引导程序:79) 在Module ../ src / main.ts(main.ts:1) 在 webpack_require (引导程序:79)
我比较了ngxs / store 2.0.0和3.6.0与Selector()方法装饰器之间的区别,并且代码中有一些区别,但是在我的情况下,描述符没有定义。在TS docs上这样写:
注意如果您的脚本目标是,则属性描述符将是未定义的 小于ES5。
我使用ES6 ...
tsconfig:
{
"compileOnSave": false,"compilerOptions": {
"baseUrl": "./","outDir": "./dist/out-tsc","sourceMap": true,"declaration": false,"downlevelIteration": true,"experimentalDecorators": true,"module": "esnext","moduleResolution": "node","importHelpers": true,"target": "es2015","typeRoots": [
"node_modules/@types"
],"lib": [
"es2018","dom"
]
},"angularCompilerOptions": {
"fullTemplateTypeCheck": true,"strictInjectionParameters": true,"enableIvy": true,"target": "es2015"
}
}
编辑:
经过许多小时的尝试新项目和变体之后...从angularCompilerOptions中删除目标属性可以达到目的:
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,"target": "es2015"
},
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)