角4 - 不能添加/删除密封数组元素

问题描述:

嗨,我收到以下错误试图插入元素的数组:角4 - 不能添加/删除密封数组元素

无法添加/删除密封数组元素

我得到的数据使用apollo-angular(GraphQL客户端)。数据恢复得很好。

这里是我的代码: main.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"} 
    ] 
} 
+0

你从服务中获得数据然后清除它?同时更新您的示例json文件 – Aravind

+0

我从调用graphql的服务获取数据。 –

在服务,当您收到回应:

代替:

this.messages = result.data.nodes; 

使用:

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

的问题是与阿波罗-client包,我用我的GraphQL服务器进行通信,并获取数据。

似乎apollo客户端自动深度冻结所有服务器响应。 我已经在他们的github回购协议中打开了一个相关问题: https://github.com/apollographql/apollo-client/issues/1909