Angular 2 form Change event with a parameter
Angular 2 form Change event with a parameter
下面是 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>
我很确定,您应该能够像这样将 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>
下面是 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>
我很确定,您应该能够像这样将 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>