dimanche 26 juillet 2020

Typescript: iterate through checkbox (made by ngfor) and print value of each checkbox

I want to get value (console.log(somevalue)) from each of my checkbox generated by ngfor . My form is displaying OK.

Here is code :

<form>
  <div class="form-group row" *ngFor="let firstColumn of mapMenusFirstColumn; index as i;">
    <label class="col-4"></label>
    <div class="col-8">
      <div class="custom-control custom-checkbox custom-control-inline"
        *ngFor="let secondColumn of this.getSecondColumn(this.mapMenu,firstColumn); index as j;">
        
        <input name="checkbox" id="checkbox" type="checkbox" class="custom-control-input"
          value=>
        <label for="checkbox" class="custom-control-label"></label>
      </div>
    </div>
  </div>
  <div class="form-group row">
    <div class="offset-4 col-8">
      <button name="submit" type="submit" class="btn btn-primary">Submit</button>
    </div>
  </div>
</form>

Here is design :

enter image description here

I need to iterate though all of my checkbox and console.log() each check box value. Please help me

(Note that : see how I generated Id and Name - it is like :

when name 1 id is 1_1 , 1_2 ..

when name 2 id is 2_1, 2_2, 2_3, ...

Should I change my id , name implementation for this purpose ? If so please tell me about it.)




Aucun commentaire:

Enregistrer un commentaire