gpt4 book ai didi

javascript - Angular 4 typescript Cordova Camera 插件错误 "Property ' camera' does not exist on type 'Navigator' "

转载 作者:搜寻专家 更新时间:2023-11-01 09:31:20 27 4
gpt4 key购买 nike

我尝试使用 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 Camera 插件错误 "Property ' camera' does not exist on type 'Navigator' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47055198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com