title: ionic 2 check-box value
body: <p>I am referring <a href="https://stackoverflow.com/questions/42437889/ionic-2-read-checkbox-value">Ionic 2 read checkbox value</a> code in the same manner as described in answer. But I am getting error message in console that:</p>
  
  <pre><code> Cannot read property 'indexOf' of undefined
  </code></pre>
  
  <p>Below is my home.html code:</p>
  
  <pre><code> &lt;form #leadsForm = "ngForm"&gt;
      &lt;ion-item&gt;
          &lt;ion-label&gt;Assign to: &lt;/ion-label&gt;
          &lt;ion-select [(ngModel)]="saleRep" name="saleRep"&gt;
              &lt;ion-option *ngFor="let agency of agencyReps;let i = index;" value="{{agencyRepsIds[i]}}"&gt; {{ agencyReps[i] }}&lt;/ion-option&gt;                        
          &lt;/ion-select&gt;
      &lt;/ion-item&gt;
      &lt;button ion-button (click)="assignLeads()" block&gt;Assign&lt;/button&gt;
  
      &lt;ion-list &gt;
          &lt;ion-item *ngFor="let t of leads;"&gt;
              &lt;h2 [ngClass]="t.status"&gt;{{t.fname}} {{t.lname}} | {{ t.status}}&lt;/span&gt;&lt;/h2&gt;
              &lt;label&gt;
                  &lt;input type="checkbox" value="{{t}}" [checked]="cbChecked.indexOf('t') &gt;= 0" (change)="updateCheckedOptions(t, $event)" /&gt;
              &lt;/label&gt;
          &lt;/ion-item&gt;
      &lt;/ion-list&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>leads in *ngFor is fetching directly from backend and the leads data is listing perfectly fine.</p>
  
  <p>home.ts is as follows:</p>
  
  <pre><code>  export class Leads {
      cbChecked: string[];
      saleRep;
  
      constructor() { }
  
      updateCheckedOptions(chBox, event) {
          var cbIdx = this.cbChecked.indexOf(chBox);
  
          if(event.target.checked) {
            if(cbIdx &lt; 0 ){
                 this.cbChecked.push(chBox);
               console.log(chBox);
            }
          } else {
            if(cbIdx &gt;= 0 ){
               this.cbChecked.splice(cbIdx,1);
                console.log(cbIdx);
            }
          }
      }
  
      assignLeads(){
          console.log('Selected Representative',this.saleRep)
          console.log('CheckBox Value',this.cbChecked);
      }
  
   }
  </code></pre>
  
  <p>Thank you.</p>