角度 4 - 无法添加/删除密封的阵列元素



嗨,我在尝试将元素插入数组时遇到以下错误:

无法添加/删除密封的阵列元素

我使用 apollo-angular(GraphQL 客户端(获取数据。数据恢复得很好。

这是我的代码: 主.html:

<div class="chats">
<chat *ngFor="let chat of activeChats; let i = index" [chat]="activeChats[i]" (close)="removeChat(i)"></chat>
</div>

聊天组件 :

@Component({
selector: 'chat',
templateUrl: './chat.component.html'
})
export class ChatComponent {
@Input() chat : Chat
constructor(
private chatService : ChatService
) {}
getNextPage(){
this.chatService.getMessages(this.chat.id, this.chat.messages[0].sentTime).subscribe(msgs=>{
// The error thrown here
this.chat.messages.splice(0,0,...(msgs || []));
})
}
}

聊天数据示例结构:

{
id : "234234234",
messages : [
{id:"2341112", sentTime:"2017-07-05T17:14:07.396Z"},
{id:"2341342", sentTime:"2017-06-05T17:14:07.396Z"}
]
}

在服务中,当您收到响应时:

相反:

this.messages = result.data.nodes;

用:

this.messages = [...result.data.nodes];

问题出在 apollo-client 包上,我正在使用它与我的 GraphQL 服务器通信并获取数据。

似乎apollo-client会自动深度冻结所有服务器响应。 我已经在他们的 github 存储库上打开了一个相关问题: https://github.com/apollographql/apollo-client/issues/1909

最新更新