gpt4 book ai didi

javascript - Phonegap pictureSource.PHOTOLIBRARY 不适用于 Angular

转载 作者:太空狗 更新时间:2023-10-29 19:35:49 25 4
gpt4 key购买 nike

没有 Angular 它工作正常:

<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Album</button>
<script type="text/javascript">
function onPhotoURISuccess(imageURI) {
alert(imageURI)
}

function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.imageURI,
sourceType: source });
}

function onFail(message) {
alert('Failed because: ' + message);
}
</script>

但是当我尝试使用 angular 2 并且我的代码不起作用时:

<button (click)="getPhoto(pictureSource.PHOTOLIBRARY)">From Photo Album</button>

getPhoto(source) {
alert(111);
navigator.camera.getPicture(this.onSuccess, this.onFail, { quality: 50,
destinationType: navigator.camera.DestinationType.imageURI,
sourceType: source });
}
onSuccess(imageData) {
this.photo = imageURI;
}
onFail(message) {
alert('Photo not loaded, because: ' + message);
}

当我点击按钮时,getPhoto 函数不起作用。因为函数中有pictureSource.PHOTOLIBRARY。

最佳答案

此 API 可能未由 Angulars 专区修补。尝试明确使用区域

constructor(private zone: NgZone) {}

getPhoto(source) {
alert(111);
zone.run(() => {
navigator.camera.getPicture(this.onSuccess, this.onFail, { quality: 50,
destinationType: navigator.camera.DestinationType.imageURI,
sourceType: source });
});
}

(不确定语法是否正确,我不是 TS 开发人员)

关于javascript - Phonegap pictureSource.PHOTOLIBRARY 不适用于 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852464/

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