I am using angular, trying to pass an object to the web worker for the background process. the class is
Article{
method1();
propertyA;
}
addEventListener('message', ({ data }) => {
// if without plainToClass, how to call article.method1()
data.article=plainToClass(Article, data.article);
console.log(data.article.method1());
});
Because in the web worker thread, I want to use article.method1(),
After the object is passed to web worker, it becomes an object that does not have methods but only properties. Why is this? pass as a string?
Tried to use
plainToClass()
to convert the passed obj to an Object with method, which in main thread I am able to do so, load string and convert to Class object. but in web worker, it complains aboutReflect.getMetadata is not a function
. Which seems it cannot find the importedimport 'reflect-metadata'
inpolyfills.ts
Answer:
It turns out I need to import this in Article class file
import 'reflect-metadata';
export class Article implements Clonable{
}