【发布时间】:2019-05-30 22:26:46
【问题描述】:
在我的 html 中,我有一个标签,其中显示了我为特定实例提交给服务器的大量图像。我现在的问题是,当我上传图像时,它不会刷新图像计数,我必须关闭移动应用程序并再次打开才能看到图像计数器上升/。
图片上传成功后我尝试更改Typescript代码中的变量,但String没有改变
<StackLayout class="m-10">
<Label [text]="imagesCount + ' Photos Uploaded'" verticalAlignment="center" class="lbl-info" horizontalAlignment="center" textWrap="true"></Label>
</StackLayout>
get imagesCount() {
this._imagesCount = workAttachments.length;
return this._imagesCount;
}
我希望图像标签从 0 Photos Uploaded 变为 1 Photos Uploaded
-- 编辑--
这就是我上传图片的方式
doFileUpload(file: any) {
let actualFile = fs.File.fromPath(file);
let base64 = android.util.Base64.encodeToString(actualFile.readSync(), android.util.Base64.NO_WRAP);
let workOrderAttachment = new WorkOrderAttachment(new Attachment(base64, file.replace(/^.*[\/]/, ''), 0), WorkOrderAttachmentType.PHOTO, '');
this._service.workOrderAttachment(this.job.id, workOrderAttachment, ['id']).subscribe(result => {
if (result == null) {
UserInterfaceUtil.showError("Error Uploading images.", "");
} else {
UserInterfaceUtil.showInfo("Photos uploaded successfully.", "");
this._imagesCount += 1;
}
}, error => {
UserInterfaceUtil.handleError(error);
console.log(error);
});
}
【问题讨论】:
-
我不确定您是如何更新
workAttachments数组的。如果更新发生在 NgZone 中,那么您应该看到计数已经更新。我们需要一个可以重现问题的完整示例。
标签: nativescript nativescript-angular