name 和 info 的 getter 实际上并不针对特定的表单控件,因为您的 person 是一个 formArray,例如 this.form.get('person.name'); 在您的表单中不存在.您需要做的是,对每个表单组使用迭代并使用其控件定位该组,因此您的模板应如下所示:
<div *ngFor="let p of form.controls.person.controls; let i = index"[formGroupName]="i"><label for="name">name:</label><input formControlName="name" id="name" type="text"><!--检查这个组中的名字是否有错误--><div *ngIf="p.controls.name.dirty"><div *ngIf="p.hasError('required', 'name')">必需</div>
Your getters for name and info actually don't target the specific form controls, since your person is a formArray, for example this.form.get('person.name'); does not exist in your form. What you need to do, is use the iteration for each formgroup and target that group with its controls, so your template should look like this:
<div *ngFor="let p of form.controls.person.controls; let i = index"
[formGroupName]="i">
<label for="name">name:</label>
<input formControlName="name" id="name" type="text">
<!-- check if the name in this group has the error -->
<div *ngIf="p.controls.name.dirty">
<div *ngIf="p.hasError('required', 'name')">Required</div>
</div>
</div>
Furthermore a suggestion is, that you can shorten your code a bit and remove a method that isn't really needed for initializing/adding formgroup to your array, so here I removed the addNewRow, initItemRows can be called when you want a new row added.