dimanche 19 avril 2020

Dynamic checkbox in angular 8

I am working with dynamic checkbox in angular 8... i am getting checkbox names list form a method that result i set as array.. and i have binded that array in html.. but when i submit ngform it returns null value. i am adding my code here

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="" name="" value="" (change)="toggleVisibility($event)">
              <label></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"></option>
              </select>
            </div>
          </div>
        </div>



Aucun commentaire:

Enregistrer un commentaire