所以我试图添加动态表单,添加了它,但是却出现了控制台错误:
await BackgroundFetch.registerTaskAsync(taskName, {
setMinimumIntervalAsync: 5,
stopOnTerminate: false
});
await BackgroundFetch.setMinimumIntervalAsync(5);
alert('task registered');
console.log('task registered');
所以请帮助我解决问题。所以下面是html和ts文件。因此,当尝试在构造函数中加载页面时,添加默认字段,并在添加时单击,将动态表单添加到formarray
Cannot find control with path: 'members -> 0 -> '
ts文件
<form [formGroup]="memberDetails">
<div formArrayName="members" *ngFor="let item of memberDetails.get('members').controls; let i=index;">
<div class="form-row memberform-container" [formGroupName]="i" >
<!-- {{currentFormIndex}} -->
<div class="form-group col-lg-3">
<label for="firstname">First Name <em class="required">*</em></label>
<input type="text" [formControlName] ="firstname" class="form-control" id="firstname">
</div>
<div class="form-group col-lg-3">
<label for="middlename">Middle Name</label>
<input type="text" formControlName ="middlename" class="form-control" id="middlename">
</div>
<div class="form-group col-lg-3">
<label for="lastname">Last Name <em class="required">*</em></label>
<input type="text" formControlName ="lastname" class="form-control" id="lastname">
</div>
<div class="form-group col-lg-3">
<label for="suffix">Suffix</label>
<select formControlName ="suffix" id="suffix" class="form-control">
<option value ="">Select</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
</select>
</div>
<div class="form-group col-lg-3">
<label for="dob">Date of Birth <em class="required">*</em></label>
<!-- <form class="form-inline"> -->
<div class="form-group">
<div class="input-group">
<input formControlName ="dob" class="form-control" placeholder="yyyy-mm-dd" name="dp"
ngbDatepicker #d="ngbDatepicker" [placement]="placement"
[positionTarget]="buttonEl">
<div class="input-group-append">
<button #buttonEl class="btn btn-outline-secondary calendar" (click)="d.toggle()"
type="button"></button>
</div>
</div>
</div>
<!-- </form> -->
</div>
<div class="form-group col-lg-4">
<label for="dob">Gender <em class="required">*</em></label>
<div class="row ml-0">
<button type="button" (click)="save()" class="btn" style="border: 1px solid lightgray; border-radius:0;">Male</button>
<button type="button" (click)="save()" class="btn" style="border: 1px solid lightgray;border-radius:0;">Female</button>
</div>
</div>
<div class="form-group col-lg-12">
<label for="dob">Is primary Applicant applying for health coverage? (Choose "Yes" if he or she wants to apply for a private
health plan or Medicaid/Maryland Childern's Health Program, even if he or she is already enrolled through Maryland Health Connection.)<em class="required">*</em></label>
<div class="row ml-0">
<button type="button" (click)="save()" class="btn" style="border: 1px solid lightgray; border-radius:0;">Yes</button>
<button type="button" (click)="save()" class="btn" style="border: 1px solid lightgray;border-radius:0;">No</button>
</div>
</div>
<!-- <custom-radio-button></custom-radio-button> -->
</div>
</div>
</form>
答案 0 :(得分:0)
只需更新此行:
<input type="text" [formControlName] ="firstname" class="form-control" id="firstname">
到
<input type="text" formControlName ="firstname" class="form-control" id="firstname">
说明: 方括号[]告诉Angular评估模板表达式,这意味着它将查找具有此名称的变量/函数。 如果要保留此语法,则需要在ts内声明一个名为firstname的变量,其名字为firstname:
...
firstname = firstname ;
...