Angular 8 - camera loading error
See original GitHub issueUnable to find the scanner either on init or AfterviewInit after upgrade to Angular 8, Zxing - 1.7
typescript :34.5
It works perfect with Angular 7.
HTML
<zxing-scanner #scanner [autostart]="true"
[device]="currentDevice" (scanFailure)="handleScanFailure($event)" (scanError)="handleScanError($event)" (scanComplete)="handleScanComplete($event)" (scanSuccess)="handleScanSuccess($event)" [formats]="allowedFormats"
></zxing-scanner>
TS (with static: true)
@ViewChild('scanner',{static:false}) scanner: ZXingScannerComponent;
private initCamera(): void {
this.scanner.camerasFound.subscribe((devices: MediaDeviceInfo[]) => {
this.hasDevices = true;
this.availableDevices = devices;
if (this.availableDevices.length > 1) {
const defaultCamera = this.availableDevices.filter(e => e.label.toLocaleLowerCase().indexOf('back') > -1);
if (defaultCamera !== null && defaultCamera !== undefined) {
this.currentDevice = defaultCamera[0];
} else {
this.currentDevice = this.availableDevices[0];
}
} else {
this.currentDevice = this.availableDevices[0];
}
});
}
Error:
The device
must be a valid MediaDeviceInfo or null.
Edit: added code formatting
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Problem running an Angular 4 project and in using web-cam ...
it's causing problems using the webcam and showing this error: [Deprecation] getUserMedia() no longer works on insecure origins. To use this ...
Read more >NG0100: Expression has changed after it was checked - Angular
This error commonly occurs when you've added template expressions or have begun to implement lifecycle hooks like ngAfterViewInit or ngOnChanges . It is...
Read more >Ngx Webcam with angular | Capturing image the live image
In this video you will learn how to access webcam in angular. How to capture image and preview an image using ngx-webcam in...
Read more >ngx-webcam - npm
A simple Angular webcam component. Pure & minimal, no Flash-fallback. See the Demo! Plug-and-play. This library contains a single module ...
Read more >Angular Debugging "Expression has changed": Explanation ...
And here is what the component looks like when the data is loading: Material Data Table. To find out why the "Expression has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure.
HTML:
TS:
Edit: added propper syntax highlighting.
Thank you @ymallikreddy521 . I’m locking this now for clarity, please anyone reading this feel free to open new issues.