Cannot get Camera plugin to work


#1

Hi guys.

I’m trying to get the camera plugin to work as described in the documentation (https://ionicframework.com/docs/native/camera/)

The plugin is installed correctly everything looks fine, but when I open the page all I’m getting in the logcat is:

file:///android_asset/www/build/main.js: Line 79072 : EXCEPTION: Error in ./HomePage class HomePage - inline template:15:4 caused by: No provider for Camera!

The above error is from an Android device, I understood that it won’t work using ionic serve but I thought it will work on a device.

Can somebody please shade some light on what I might be doing wrong?


#2

Hi include in your page the Camera provider like this

@Component({
selector: ‘page-camera-test’,
templateUrl: ‘audio-camera.html’,
providers: [Camera]
})
export class CameraTestPage {

Best regards


#3

THANK YOU!

It would be helpful if it was in the documentation / example. I spend about 1,5 hour looking for the solution before posting the question and it was so simple…


#4

You mean like it is in the documentaion of Ionic Native? https://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module


#5

Now I feel embarrassed… :flushed:


#6

I think @Sujan12’s answer should be the accepted answer. The currently accepted one is recommending putting providers at the component level instead of the app level. That’s only desirable in fairly rare circumstances, and I don’t think this is one of them. People coming across this thread should be declaring native providers in their app module, not in components.


#7

Agreed and marked @Sujan12’s answer as the correct one.


#8

I have imported the camera plugin to app.module.ts and it to providers , but still get this error No Provider For Camera


#9

If you are lazily loading your pages, you must also put it in the page modules that reference it.