我正在使用Angular 8中的动态复选框...我正在将复选框名称列表形成一种方法,该方法导致我将其设置为数组..并且我已经将该数组绑定为HTML ..但是当我提交ngform时,它返回null值。我在这里添加我的代码
additionalCoverArray: Array<AdditionalCovers> = [];
GetQueryAdditionalCovers() {
this._getCheckboxvalueService.getCheckBoxValues("GetAdditionalCovers").then(result => {
this.checkBoxes = result;
this.additionalCoverArray = this.checkBoxes;
console.log(this.additionalCoverArray);
});
}
in html
div class="additionalcovers-form">
<form #additionalCoversForm="ngForm" class="col-md-12" (ngSubmit)="onSubmit(additionalCoversForm.value)">
<div class="row" *ngIf="additionalCoverArray">
<div class="col-md-6">
<div class="row">
<div class="col-md-6" *ngFor="let objCheckbox of additionalCoverArray; let i=index">
<input type="checkbox" [(ngModel)]="objCheckbox.isMandatory" id="{{objCheckbox.displayValue}}" name="{{objCheckbox.displayValue}}" value="{{objCheckbox.displayValue}}" (change)="toggleVisibility($event)">
<label>{{ objCheckbox.displayValue }}</label>
</div>
<div class="col-md-6">
<label>No Years</label>
<select (change)="change($event)" [(ngModel)]="noYearsArray.noYears" name="noYears" [ngModelOptions]="{standalone: true}">
<option *ngFor="let objNoYears of noYears" [value]="objNoYears.displayValue">{{objNoYears.displayValue}}</option>
</select>
</div>
</div>
</div>