January 2018
Intermediate to advanced
332 pages
7h 36m
English
As the component loads, we will want to set up the worker so that it is not something that we have to repeat several times. So, imagine if there were a way in which you can set up something conditionally and perform an action only when you want it to. In our case, you can add it to the constructor or to any of the lifecycle hooks that denote what phase the component is in such as OnInit, OnContentInit, OnViewInit and so on, which are provided by Angular as follows:
this.worker = new Worker('scripts.bundle.js');this.worker.addEventListener('message', (e) => { this.result = e.data;});
Once initialized, we then use the addEventListener() method to listen for any new messages—that is, results coming from our worker. ...
Read now
Unlock full access