eisberg-labs / ngx-barcode-scanner

Angular Barcode scanner using Quagga

Home Page:https://ngx-barcode-scanner.amarjanica.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reset Service

RichardTezbirr opened this issue · comments

Hi Ama,
my question is, how do I reset the scanner ? I do not want user to do refresh of whole page everytime when unsuccessful scan was made, or when the barcode is not found in database. I would rather to have trigger which reset the whole service.

I have tried to call ngOnDestroy and ngOnInit on scanner-object. The camera open again, but it doesn't scan anymore because of unsubscription.

core.js:6142 ERROR Error: Uncaught (in promise): ObjectUnsubscribedError: object unsubscribed
at resolvePromise (zone-evergreen.js:1213)
at zone-evergreen.js:1283
at ZoneDelegate.invokeTask (zone-evergreen.js:406)
at Object.onInvokeTask (core.js:28500)
at ZoneDelegate.invokeTask (zone-evergreen.js:405)
at Zone.runTask (zone-evergreen.js:178)
at drainMicroTaskQueue (zone-evergreen.js:582)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:491)
at invokeTask (zone-evergreen.js:1600)
at XMLHttpRequest.globalZoneAwareCallback (zone-evergreen.js:1637)

It happens also, when you go to other page and come back to scanner:

ObjectUnsubscribedErrorImpl {message: "object unsubscribed", name: "ObjectUnsubscribedError"}
message: "object unsubscribed"
name: "ObjectUnsubscribedError"
[[Prototype]]: Error

It is related to the service, which we do not have access to. Following
https://stackoverflow.com/questions/67235013/objectunsubscribederrorimpl-on-an-observable-in-a-template-in-angular

When you unsubscribe directly from a subject it will be closed. Whenever you then try to resubscribe to it it will throw the ObjectUnsubscribedError.

Woudn't it be the best to have such a trigger, which after calling resets the service ? Or should I just configure config for this use-case ? What would be the best solution for that ?

Thanks in advance.

Hi, looking at the code, this line is the problem .
I'm not sure why I went in that direction....stopping the service after first recognition. This should be called on ngDestroy.
What you could do for now is call NgxBarcodeScannerService method start, until I fix it.
Update should be by the end of the weekend. Thanks for reporting!

I see where's the bug, in the service. Fix should be quick.

#13 should fix your issue. new version is 2.0.1

Hi, thank you for your solution, it solved the problem.