No provider for Camera! injectionError
There's a problem with the auto generated import
statement. You need: import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
you need to install camera plugins first by using two commands
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera
after that in your app.module.ts you need to import
that plugins
and change your provider
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HttpModule } from '@angular/http';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { CamaraExampalePage } from "../pages/camara-exampale/camara-exampale";
import { Camera} from '@ionic-native/camera';
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
CamaraExampalePage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
CamaraExampalePage
],
providers: [
Camera,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
You need to set Camera as provider in app.module.ts
import { Camera } from '@ionic-native/camera';//import in app.module.ts
//...
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
Camera //here
]
While I Serve the project it shows Runtime Error
NOTE: Cordova plugins do not work in ionic serve.. You need to use emulator/device.
Also, include your plugin code within this.platform.ready()
and check if cordova is available using this.platform.is('cordova')
import { Platform } from 'ionic-angular'; //import Platform
//...
constructor(public platform:Platform){}
//...
takePhoto() {
this.platform.ready().then(() => {
if(this.platform.is('cordova')){
this.camera.getPicture(this.options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
}
})
}