Ngrx 使我的分派对象只读
我有以下代码行:
this.carInformation.subModel = [this.submodel.value];
this.store.dispatch(saveCriteria({ criteria: this.carInformation }));
当我的应用程序重新运行这两行时,我在第一行收到以下错误:
无法分配给对象“[object Object]”的只读属性“subModel”
为什么是 carInformation突然变成只读了?
我确实注意到使用以下代码行我的对象的可写属性现在为 false:
Object.getOwnPropertyDescriptor(this.carInformation, 'subModel');
我设法通过将调度移到其他地方来解决此问题,但我认为我可以重新编辑我的对象并重新调度它?
I've got the following lines of code:
this.carInformation.subModel = [this.submodel.value];
this.store.dispatch(saveCriteria({ criteria: this.carInformation }));
When my app re-runs these two lines, I get the following error on the first line:
Cannot assign to read only property 'subModel' of object '[object Object]'
Why is carInformation suddenly read only?
I did notice using the following line of code that the writable property of my object is now false:
Object.getOwnPropertyDescriptor(this.carInformation, 'subModel');
I managed to fix this by moving the dispatch elsewhere, but I would've figured that I could re-edit my object and re-dispatch it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
this.submodel.value
的引用被分派到存储。因为存储具有不可变的运行时检查,所以该引用被“锁定”并在发生更改时抛出异常。
The reference of
this.submodel.value
is dispatched to the store.Because the store has immutable runtime checks, that reference is "locked" and throws if it's changed.