大佬教程收集整理的这篇文章主要介绍了cordova – 没有相机供应商! injectionError,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我发送app.module.ts,html页面,并输入脚本页面.请看一看.
app.module.ts
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 { httpR_285_11845@odule } 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 { CameraExamplePage } from "../pages/camara-example/camara-example"; @NgModule({ declarations: [ MyApp,AboutPage,ContactPage,HomePage,TabsPage,CameraExamplePage ],imports: [ BrowserModule,httpR_285_11845@odule,IonicModule.forRoot(MyApp) ],bootstrap: [IonicApp],entryComponents: [ MyApp,providers: [ StatusBar,SplashScreen,{provide: ErrorHandler,useClass: IonicErrorHandler} ] }) export class AppModule {}
相机拿Html页面
<ion-header> <ion-navbar> <ion-title>camaraExample</ion-title> </ion-navbar> </ion-header> <ion-content padding> <button ion-button color="dark" (click)="takePhoto()" > Take Photo </button> <img [src]="imageURL" *ngIf="imageURL"> </ion-content>
import { Component } from '@angular/core'; import { IonicPage,NavController,NavParams } from 'ionic-angular'; import { Camera,CameraOptions } from '@ionic-native/camera' @IonicPage() @Component({ SELEctor: 'page-camara-example',templateUrl: 'camara-example.html',}) export class CameraExamplePage { imageURL constructor(public navCtrl: NavController,public navParams: NavParams,public camera: Camera) { } ionViewDidLoad() { console.log('ionViewDidLoad CameraExamplePage'); } takePhoto() { const options: CameraOptions = { quality: 100,desTinationType: this.camera.DesTinationType.DATA_URL,encodingType: this.camera.EncodingType.JPEG,mediaType: this.camera.MediaType.PICTURE } this.camera.getPicture(options).then((imageData) => { // imageData is either a base64 encoded String or a file URI // If it's base64: //let base64Image = 'data:image/jpeg;base64,' + imageData; this.imageURL = imageData },(err) => { // Handle error }); } }
import { Camera } from '@ionic-native/camera';//import in app.module.ts //... providers: [ StatusBar,useClass: IonicErrorHandler},Camera //here ]
注意:Cordova插件在离子服务中不起作用..您需要使用模拟器/设备.
另外,在this.platform.ready()中包含你的插件代码,并使用this.platform.is(‘cordova’)检查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 }); } }) }
以上是大佬教程为你收集整理的cordova – 没有相机供应商! injectionError全部内容,希望文章能够帮你解决cordova – 没有相机供应商! injectionError所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。