I have a dynamic formControl where addControl is as follows in my component.ts file:
//...
this.reportList = this.data.reportList;
for (let i = 0; i < this.reportList.length; i++) {
const key = this.reportList[i].quesId+'';
this.afterActionReportForm.addControl(key, new FormControl(this.reportList[i].boardAnswers));
}
...///
my component.html file code looks as follows:
<div class="row" *ngIf="reportList && reportList.length > 0" style="padding:10px;">
<div *ngFor="let e of reportList; let i = index" class="col-sm-6" style="margin-top: 2em;">
{{i+1}}. {{e.question}}
<textarea style="width:100%" #{{e.quesId}} rows="8" cols="75" maxlength="500" formControlName="{{e.quesId}}"
class="form-control" pInputTextArea ></textarea>
<span> {{e.boardAnswers.length}} of 500 characters</span>
</div>
</div>
The display part is working fine. But the span has a count which id calculated on the fly and shows up in the UI based on what the textArea is inputed.
like for example shows 25 of 500 characters and as you keep typing the counter has to increase. I was able to do that for my static form as follows: This one works in static form:
<div class="col-sm-10">
<textarea style="width:80%" #message rows="8" cols="75" maxlength="500"
formControlName="message" class="form-control" pInputTextArea ></textarea>
<span> {{message.value?.length || 0}} of 500 characters</span>
</div>
But the same concept doesnt work for dynamic form.{{e.boardAnswers.length}} gives me value only when the page loads up, however when i type in the textArea it doesnt increment. How do I handle the same with dynamic forms. Suggestions please?