New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuaggaJS in Angular 2 breaks Template Binding #146
Comments
I did a little more investigation to see what's going on, and Angular's change detection code isn't triggered at all when |
@gelliott181, I believe this issue is related to WebWorker. Your problem should go away immediately once you set numOfWorkers to 0, which is the workaround I chose. You could also call angular zone to forcefully rerender, but this method doesn't feel clean to me. |
WebWorkers aren't an issue. I did try |
Here's an interesting behavior: I added a forced check of the component tree for change detection by injecting My callback reports I logged my |
Fix found! It comes down to TypeScript being very picky about how things are passed around. Previously I'd registered callbacks using To fix this I tried arrows again, but I replaced my anonymous function with I've pushed the working component to the reproduction repo under the |
I'm trying to pull QuaggaJS into an Angular 2 project and hit a UI snag. I was successful in implementing the livestream code, and am able to detect barcodes along with displaying the generated locator boxes on the image based on the data in result.
What I have found is an issue where QuaggaJS seems to interferes with Angular 2 template binding. After registering an arrow function as my callback to preserve
this
I attempt to assignresult.codeResult.code
to a variable in myAppComponent
classthis.lastResult
. This assignment goes fine and dandy, as I can logthis.lastResult
to the console and see the scanned info. What goes wrong is that after assigning the variable Angular 2 doesn't update the displayed value. Setting the value using a generic control (E.g. button, checkbox, click handler) works as expected.I get similar results using the constructor, the ngOnInit hook and the ngAfterViewInit hook. There's a very finite amount of places to instantiate Quagga in the Angular lifecycle and with these three out none are considered the "right way" to do things.
Reproduction repo is available at https://github.com/gelliott181/ng2-quagga-issue
To run:
npm install
to install the project (This project uses the Angular CLI)node_modules\.bin\ng s -h 0.0.0.0
to start a dev server on all interfacesThe text was updated successfully, but these errors were encountered: