我尝试使用 Cordova 构建 APK。 Web 部件代码是用 Angular 4 typescript 编写的。当 ng build 时,它给了我以下错误
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
}
);
}
}
}
最佳答案
if( navigator != undefined){
navigator.camera.getPicture(
(imageUri) => {
alert(imageUri);
},
(error) =>{
alert("Unable to obtain picture: "+error);
}, {
quality: 50,
allowEdit: true,
correctOrientation: true
}
);
}
我在openCamera函数中替换了上面的代码。发生错误是因为我试图从窗口对象访问导航器对象。
关于javascript - Angular 4 typescript Cordova相机插件错误 "Property '相机'在类型 'Navigator'上不存在”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47055198/