需要帮助更改 TS 代码中的标签文本

Need help changing Text of label in TS Code

在我的 html 上,我有一个标签,显示我为特定实例提交给服务器的图像数量。我现在的问题是,当我上传图像时,它不会刷新图像计数,我必须关闭移动应用程序并再次打开才能看到图像计数器上升/。

图片上传成功后,我尝试更改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);
        });
    }

当您在 TypeScript 中创建 get 属性 时,您需要 return 一个值。

public get imagesCount(): number {
    this._imagesCount = workAttachements.length;

    return this._imagesCount;
}

查看 "Accessors" 文档:https://www.typescriptlang.org/docs/handbook/classes.html

希望对您有所帮助。

我能正确完成这项工作的唯一方法是在表单上添加一个按钮来刷新标签。这不是做我需要的最好方法,但已经完成了。