Error cloning element from scope while using Angular and Web Workers

只谈情不闲聊 提交于 2019-12-24 08:27:18

问题


I have an Angular app and I'm trying to implement some functionality into a Web Worker. To achieve this I need to pass an object from the angular scope to the worker so it's processed and a result is generated.

I run into the following error:

Error: Failed to execute 'postMessage' on 'Worker': An object could not be cloned.

When calling worker.postMessage($scope.scopeObj);

Is there something special I have to do in order to send that object to the worker? It currently works with mock objects created manually.


回答1:


Turns out the object I was trying to send had a call to a function inside, and as this document (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#Things_that_don%27t_work_with_structured_clones) indicates, that's one of the things that are not supported on the message.

Removing the function from the object send fixed the error.



来源:https://stackoverflow.com/questions/33035854/error-cloning-element-from-scope-while-using-angular-and-web-workers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!