2

I need to create table with independent checkboxes in one of the columns. The button is styled as here (it forces input inside label). My problem is that it doesn't change states when is located in table. (Beyond table works ok)

<table>

    <thead>
       <tr>
         <th>Check</th>
       </tr>
    </thead>

    <tbody>
     <tr *ngFor="let item of items">
       <td>
         <label class="switch">
           <input type="checkbox" (click)="changed($event)">
           <div class="slider"></div>
         </label>
       </td>
     </tr>
    </tbody>

</table>

I also tried to add specific id to each input but without success.

5
  • This code is not saying very much unfortunately. What are you doing on changed method? Commented Jun 5, 2017 at 18:41
  • Nothing big yet, just log to check if changed($event) is called Commented Jun 5, 2017 at 18:54
  • could you try setting a different id AND name to each input? Commented Jun 5, 2017 at 19:00
  • I've tried too, with different id and different name Commented Jun 5, 2017 at 19:01
  • It would be interesting if you can share an example on plunker on any other collaborative web tool. Your code is very simple, I don't see how it can't fail Commented Jun 5, 2017 at 19:05

1 Answer 1

1
<table>

<thead>
   <tr>
     <th>Check</th>
   </tr>
</thead>

<tbody>
 <tr *ngFor="let item of items">
   <td>
     <label class="switch">
       <input type="checkbox" (change)="changed($event)" >

       <input type="checkbox" (change)="changed($event, item)" [checked]="item.checkbox">
       <div class="slider"></div>
     </label>
   </td>
 </tr>
</tbody>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.