在我的html上,我有一个标签,显示了我为特定实例提交给服务器的大量图像。我现在的问题是,当我上传图像时,它不会刷新图像计数,我必须关闭Mobile应用程序并再次打开以查看图像计数器上升/。
在图像成功上传后,我尝试在Typescript代码中更改变量,但字符串未更改
<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);
});
}
答案 0 :(得分:1)
在TypeScript中创建get
属性时,需要return
值。
public get imagesCount(): number {
this._imagesCount = workAttachements.length;
return this._imagesCount;
}
查看“访问器”文档:https://www.typescriptlang.org/docs/handbook/classes.html
希望有帮助。
答案 1 :(得分:0)
我能正确完成此操作的唯一方法是在窗体上添加一个按钮以刷新标签。这不是我需要的最好方法,但是它已经完成了。