Reputation: 67
I trying to build APK using Cordova. Web part code is written in Angular 4 typescript. While ng build it gives me following error
ERROR in $/AngularCordova/my-app/src/app/app.component.ts (19,26): Property 'camera' does not exist on type 'Navigator'. ERROR in $/AngularCordova/my-app/src/app/app.component.ts (23,13): Supplied parameters do not match any signature of call target.
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
}
);
}
}
}
Upvotes: 2
Views: 2458
Reputation: 67
if( navigator != undefined){
navigator.camera.getPicture(
(imageUri) => {
alert(imageUri);
},
(error) =>{
alert("Unable to obtain picture: "+error);
}, {
quality: 50,
allowEdit: true,
correctOrientation: true
}
);
}
I replace the above code in openCamera function. Error occurs because i was trying to access the navigator object from window object.
Upvotes: 2