我在我的Angular 应用程序中使用*ngFor
和all生成多个表单.当我只更改一个输入域时,提交按钮将被禁用/启用.
我希望相应输入字段的按钮在only相应表单的输入字段更改时禁用/启用,而不是在any任何表单的输入字段更改时禁用/启用.
我现在想不出解决办法,也想不出替代方案.有什么主意吗?
我的html代码:
<mat-card *ngIf="myText">
<h1 mat-header class="center">My texts</h1>
<mat-card-content>
<div *ngFor="let item of myText">
<h3 mat-subheader class="center">myText {{ item.index + 1 }}</h3>
<p class="message">{{ item.textmessage }}</p>
<form [formGroup]="myTextForm" class="myText-form" (ngSubmit)="sendPrompt(item.index)">
<mat-form-field class="full-width" *ngIf="!error">
<mat-label>Respond to text</mat-label>
<textarea
matInput
cdkTextareaAutosize
cdkAutosizeMinRows="3"
cdkAutosizeMaxRows="20"
formControlName="prompt"
required="true"
></textarea>
</mat-form-field>
<p>
<button mat-raised-button class="btn" color="primary" [disabled]="myTextForm.invalid" type="submit">
Respond
</button>
<button
mat-raised-button
color="accent"
[cdkCopyToClipboard]="item.textmessage"
>
Copy to clipboard
</button>
</p>
</form>
<mat-divider *ngIf="item.index + 1 < myText.length"></mat-divider>
</div>
</mat-card-content>
</mat-card>
任何帮助或提示都是非常感谢的.
编辑:丹尼尔·瓦涅斯的回答为我做了这件事.谢谢!