下面是用于将文件添加为表单数据的HTML。我想删除“添加”按钮并在更改$ event期间传递值(ticket.id),这将触发组件写入文件。
可以做到吗?
<tr *ngFor='let ticket of tickets'>
<td>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="form-group">
<input
type="file"
class="custom-file-input"
id="avatar" (change)="onFileChange($event)" #avatar>
</div>
<button
type="button"
(click)="onSubmit(ticket.id)"
[disabled]="form.invalid || loading"
class="btn btn-success">
Add File<i class="fa fa-spinner fa-spin fa-fw" *ngIf="loading"></i>
</button>
</form>
</td>
</tr>
答案 0 :(得分:0)
我很确定,您应该能够将ticket.id
作为第二个参数传递给change
事件,如下所示:
<tr *ngFor='let ticket of tickets'>
<td>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="form-group">
<input
type="file"
class="custom-file-input"
id="avatar"
(change)="onFileChange($event, ticket.id)"
#avatar>
</div>
</form>
</td>
</tr>