【发布时间】:2020-08-18 22:24:12
【问题描述】:
我正在尝试使用 FormArray 来获取使用 for 循环迭代的输入值。我用过primeng table,代码如下
AppComponent HTML
<div formArrayName="responses">
<p-table [value]="datas">
<ng-template pTemplate="header">
<tr style="border: none;">
<th>Question No</th>
<th>Questions</th>
<th>Data</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-data #input>
<tr>
<td>{{data.id}} </td>
<td [ngClass]="{'objectiveClass' : datas.Type != 'Narrative','narrativeClass':datas.Type == 'Narrative'}">{{ data.Question }}</td>
<td *ngIf="datas.Type != 'Narrative'">
<input class="form-control"
id="objective"
type="number"
(keyup)="patternChecking(number)"
formControlName="response"
#number/>
</td>
<td *ngIf="datas.Type == 'Narrative'">
<textarea #narrative rows="4" cols="50" maxlength="5000"
formControlName="response"
(keyup) ="charactersRemaining()"
></textarea>
<span *ngIf = "isCharactersRemaining">
<em>{{ textMaxLength - narrative.value.length }} characters remaining</em></span>
</td>
</tr>
</ng-template>
</p-table>
</div>
AppComponent TS
this.responseForm = this.fb.group({
responses : this.fb.array([this.fb.group({
response:new FormControl ('')
})])
});
我无法识别上述代码的问题。
【问题讨论】:
-
为什么是两个
this.fb?
标签: javascript angular forms primeng formarray