简体   繁体   English

Phonegap pictureSource.PHOTOLIBRARY不适用于角度

[英]Phonegap pictureSource.PHOTOLIBRARY doesn't work with angular

Without angular it's work fine: 没有角度,它的工作正常:

<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>

But when I'm trying to use angular 2 and my code doesn't work: 但是,当我尝试使用角度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);
}

When I click on the button, getPhoto function doesn't work. 当我点击按钮时,getPhoto功能不起作用。 Because of pictureSource.PHOTOLIBRARY in the function. 因为函数中有pictureSource.PHOTOLIBRARY。

This API is probably not patched by Angulars zone. Angulars区域可能无法修补此API。 Try using zone explicitely 尝试明确使用区域

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 });
  });
}

(not sure if the syntax is correct though, I'm not a TS developer) (不确定语法是否正确,我不是TS开发人员)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM