【发布时间】:2017-05-23 00:15:31
【问题描述】:
我正在尝试用相机拍照或从图库中选择一张,然后将其显示在我的视图中(就这么简单)。 但是我在 camera.takePicture 回调中设置了新的值后,头像并没有更新,如下所示。
// template
<Image col="0" [src]="avatar" class="thumb img-rounded" width="45" height="45" verticalAlignment="middle"></Image>
// component
camera.requestPermissions();
let options = {
width: this.width,
height: this.height,
keepAspectRatio: this.keepAspectRatio,
saveToGallery: this.saveToGallery,
format: 'png'
};
camera.takePicture(options)
.then(imageAsset => {
this.avatar = imageAsset // update view with new image
this.uploadImage() // upload on the server
}).catch(err => {
console.log('error---', err.message);
});
Angular 似乎没有检测到更改。我试图在视图中显示的同一张图片正在使用 nativescript-background-http 成功上传到我的服务器。
这是我的环境:
"tns-ios": "version": "3.0.0"
"tns-android": "version": "3.0.0"
"@angular/core": "4.0.0",
"tns-core-modules": "~3.0.0"
"nativescript-camera": "^3.0.0"
在 IOS 和 Android 上都发生了该问题。
我尝试使用 ApplicationRef、NgZone 和 ChangeDetectorRef 触发更改检测,但没有成功。
有没有关于如何使用相机模块拍照并将图像绑定到视图的工作示例?
谢谢
【问题讨论】:
-
你用什么库来拍照?从中的API可以澄清问题所在。另一件事是
this.avatar的值是什么,它必须是文件的真实路径而不是数据。 -
@PRAISER 我正在使用 nativescript-camera。即使我设置了
this.avatar = path-to-a-static-image-no-my-server,它也不会出现在视图中。事实上,我在“takePicture”回调中所做的任何事情都不会更新视图。 -
我的建议:首先确保
nativescript-camera脱离Angular的上下文。
标签: angular nativescript