Home Angular 10 How to access webcam in angular 10 application?

How to access webcam in angular 10 application?

by therichpost
Published: Updated: 23 comments
angular 10 webcam access

Hello to all, welcome to therichpost.com. In this post, I will tell you, how to access webcam in angular 10 application?

Guy’s this code snippet will also work in Angular 11 and Angular 12 applications.

How to access webcam in angular 10 application?
How to access webcam in angular 10 application?
Working Video

Angular 12 came and if you are new in Angular 12 then please check my old posts related to angular 12.

Post Working:

In this post, I am telling you, how to access webcam into our angular 10 application and its features and we can also take photos and in my next post, I will you, how to make video recording in angular 10 application.

Here is the code snippet and please follow carefully:

1. Very first, here are common basics steps to add angular 11 application on your machine:

npm install -g @angular/cli

ng new angularwebcam // Set Angular11 Application on your pc

cd angularwebcam // Go inside project folder

ng serve // Run project

http://localhost:4200/  //Check working Local server

2. Now run below command into your terminal to include ngx webcam package into your angular 10 application:

npm i ngx-webcam

3. Now add below code into your app.module.ts file:

...
import {WebcamModule} from 'ngx-webcam';
...
imports: [
    ...
    WebcamModule
]

4. Now add below code into your app.component.ts file:

...
import {WebcamImage} from 'ngx-webcam';
import {Subject, Observable} from 'rxjs';
...
export class AppComponent {
...
   // latest snapshot
   public webcamImage: WebcamImage = null;

   // webcam snapshot trigger
   private trigger: Subject<void> = new Subject<void>();
   triggerSnapshot(): void {
    this.trigger.next();
   }
   handleImage(webcamImage: WebcamImage): void {
    console.info('received webcam image', webcamImage);
    this.webcamImage = webcamImage;
   }
  
   public get triggerObservable(): Observable<void> {
    return this.trigger.asObservable();
   }
}

5. Finally here is the code for app.component.html file:

<webcam [height]="500" [width]="500" [trigger]="triggerObservable" (imageCapture)="handleImage($event)"></webcam>

<!-- Button Takes Photo -->
<button class="actionBtn" (click)="triggerSnapshot();">Take A Snapshot</button>

<!-- Snapshot Div where image will be shown -->
<div class="snapshot" *ngIf="webcamImage">
  <h2>Take your image or get another</h2>
  <img [src]="webcamImage.imageAsDataUrl"/>
</div>

This is it and if you have any kind of query then please watch above video or you can comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.

Jassa

Thanks

You may also like

23 comments

Julia July 12, 2020 - 9:47 am

Amazing, thank you!!!could u also show how to record a video with a camera in angular and then submit it into mysql database?

Reply
Ajay Malhotra July 12, 2020 - 10:02 am

Yes and I will make post on it soon.

Reply
Sunak July 13, 2020 - 9:03 am

video pls on how to record a video with a camera and submit it to mysql through php man

Reply
Ajay Malhotra July 13, 2020 - 3:39 pm

I am little busy but I will make it soon and I will update this.
Thanks

Reply
Damian July 15, 2020 - 12:10 pm

AMAZING! More content like this pls

Reply
Ajay Malhotra July 15, 2020 - 12:23 pm

Thank you and sure will come soon.

Reply
Sunak July 15, 2020 - 1:48 pm

Hi r u going to add recording with camera and insert to mysql of it this week?

Reply
Ajay Malhotra July 15, 2020 - 2:59 pm

Very soon.

Reply
Sunak July 16, 2020 - 10:09 am

hi possible this week to add camera record and insert it to mysql? pls

Reply
Ajay Malhotra July 16, 2020 - 10:11 am

I am working on it but same time, I have more work. But I will update on it.

Reply
Anwar July 16, 2020 - 6:26 pm

this is brilliant sir! very very impressed! you are a top angular expert. Cant find anyone using a camera in angular on the web!!!!!!!! hats off for you! pls more content like this as this has distinguished u from everyone else doing angualar on internet

Reply
Ajay Malhotra July 17, 2020 - 3:34 am

Yes sure and thanks

Reply
Mike July 17, 2020 - 5:10 pm

sir how to record video with camera

Reply
AngularBoss July 17, 2020 - 5:29 pm

It is not possible to record a video with ngx-webcam

Reply
Alan July 17, 2020 - 5:56 pm

mike its not possible to record video with it

Reply
Sunak July 18, 2020 - 12:50 pm

Sir do u know what could be used to record a video with on angular? Seeing as ngx-webcam doesn’t work for video recording.

Reply
Ajay Malhotra July 19, 2020 - 5:51 am

yes ngx-webcam doesn’t work for video recording. I will find other way. Thanks

Reply
Harukal July 19, 2020 - 4:02 pm

If you find other way, can you let us know? Could you please do it this month or start of August? Really need it boss

Reply
Ajay Malhotra July 19, 2020 - 4:18 pm

Sure…

Reply
Harukal July 23, 2020 - 11:03 pm

Boss, do you know how to record the video, did you find a way?

Reply
UMan September 11, 2020 - 1:25 am

hi ser. how to save this video in my api serve.

Reply
UMan September 11, 2020 - 1:27 am

hi ser. how to save this image in my api serve.

Reply
Ajay Malhotra September 11, 2020 - 4:25 am

You can try video.js.

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.