【发布时间】:2019-02-27 22:20:38
【问题描述】:
我需要弄清楚如何使用响应式表单在 Angular 中为编辑模式修补图像。后端需要图像,所以我需要弄清楚如何修补它。 我读到您无法在输入类型 =“文件”中进行修补。它不支持吗?所以我想问一下这背后的想法是什么?因为它是后端需要的。它带有其他输入字段,因此我需要修补图像,因为用户可能不想更改图像而是其他输入字段。请在下面查看我的代码。正如您所看到的,我在 HTML 中显示图像并且我没有在 TS 中修补它,因为 input type="file" 似乎可以读取它。谢谢。
HTML
<label class="col-sm-4 col-form-label">Featured Image</label>
<img class="mb-2" [src]="getUrl(tour.images[0].image)" height="200px" width="350px">
<input type="file" (change)="onSelectFeaturedImage($event)" class="form-control"
formControlName="featured_image">
<label class="col-sm-4 col-form-label">Travel Dates</label>
<div class="col-sm-4">From
<input type="date" class="form-control" formControlName="travel_date_from">
TS
patchValues() {
this.tourForm.patchValue({
travel_date_from: this.tour.date_from
});
this.setAsTouched(this.tourForm);
}
【问题讨论】:
-
请澄清您的问题,这令人困惑。
-
@FussinHussin。对不起,请通读。这是我得到的最好的解释。
标签: angular angular-reactive-forms angular-forms angular4-forms