2017-11-01 9 views
1

Cordovaを使用してAPKを構築しようとしています。 Webパーツコードは、Angular 4タイスクリプトで書かれています。 プロパティ 'カメラ' 'タイプに存在しません:それを構築することはngの$/AngularCordova /私のアプリ/ SRC /アプリ/ app.component.ts(19,26)でAngular 4 typescript Cordova Camera Plugin error "タイプ 'Navigator'にプロパティ 'camera'がありません"

ERRORは私に次のエラーを与えながら、ナビゲータ 'をクリックします。 $/AngularCordova/my-app/src/app/app.component.ts(23,13)のエラー: のパラメータが呼び出しターゲットのシグネチャと一致しません。

import { Component, OnInit } from '@angular/core'; 

declare let cordova: any; 
declare let navigator: any; 
let device; 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent implements OnInit { 
    title = 'angular app'; 
    ngOnInit(){ 
     this.deviceinfo(); 
    } 
    deviceinfo(){ 

     document.addEventListener('deviceready',() => { 
     alert("On device ready event"); 
      try{ 
       alert('Using Cordova plugins with Angular 4. Cordova version: '); 
      }catch(e){ 
       alert("Exception occures"+ e) 
      } 
     }, false) 
    } 
    openCamera() { 
     if(window.navigator != undefined){ 
     window.navigator.camera.getPicture(
      (imageUri) => { 
      alert(imageUri); 
      }, 
      (error) =>{ 
      alert("Unable to obtain picture: " + error, "app"); 

      }, { 
       quality: 50, 
       allowEdit: true, 
       correctOrientation: true //Corrects Android orientation quirks 
      } 
     ); 

    } 
    } 
} 

答えて

1
if(navigator != undefined){ 
    navigator.camera.getPicture(
    (imageUri) => { 
     alert(imageUri); 
    }, 
    (error) =>{ 
     alert("Unable to obtain picture: "+error); 

    }, { 
     quality: 50, 
     allowEdit: true, 
     correctOrientation: true 
    } 
); 

} 

私はopenCamera機能で上記のコードを置き換えます。エラーは、ウィンドウオブジェクトからナビゲータオブジェクトにアクセスしようとしたために発生します。

関連する問題