cordova – 没有相机供应商! injectionError

cordova – 没有相机供应商! injectionError,第1张

概述我是Ionic 2的初学者.我想在Ionic中使用相机.我按照 https://ionicframework.com/docs/native/camera/教程. 我已经安装了cordova-plugin-camera插件并使用cli代码安装了离子原生/相机. 当我为项目服务时,它显示运行时错误: Uncaught(in promise):Error: No provider for Camera 我是Ionic 2的初学者.我想在Ionic中使用相机.我按照 https://ionicframework.com/docs/native/camera/教程.
我已经安装了cordova-plugin-camera插件并使用cli代码安装了离子原生/相机.

当我为项目服务时,它显示运行时错误:

Uncaught(in promise):Error: No provIDer for Camera! 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 { 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 { CameraExamplePage } from "../pages/camara-example/camara-example";@NgModule({  declarations: [    MyApp,AboutPage,ContactPage,HomePage,TabsPage,CameraExamplePage  ],imports: [    browserModule,httpModule,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>

** TypeScript文件**

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  }); }}
解决方法 您需要在app.module.ts中将Camera设置为提供程序

import { Camera } from '@ionic-native/camera';//import in app.module.ts //... provIDers: [    Statusbar,useClass: IonicErrorHandler},Camera //here  ]

While I Serve the project it shows Runtime Error

注意: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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1000713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存