title: Get selected checkboxes values in Angular 5
body: <p>I have a checkbox list control and am trying to get checked values into an array.</p>
  
  <p>My models:</p>
  
  <pre><code>export class Order {
      Products: Product[];
      SelectedProducts: string[];
  }
  
  export class Product {
      Id: number;
      Title: string;
  }
  </code></pre>
  
  <p>The snippet goes through the <code>Product</code> property and displays them as checkboxes:</p>
  
  <pre><code>    &lt;div *ngFor="let product of orderService.order.Products"&gt;
  
          &lt;label&gt;
              &lt;input type="checkbox" name="orderService.order.Products" value="{{product.Id}}" [(ngModel)]="product.checked" /&gt;
              {{product.Title}}
          &lt;/label&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>I can get the list of <code>orderService.order.Products</code> values from the checkboxes but how to filter them to get only checked values when submitting?</p>
  
  <p>I based my code on the @ccwasden answer here: <a href="https://stackoverflow.com/questions/34997128/angular-2-get-values-of-multiple-checked-checkboxes">Angular 2: Get Values of Multiple Checked Checkboxes</a> but my <code>Product</code> model does not have the <code>checked</code> property and it shouldn't have.</p>
  
  <p>In my component I have:</p>
  
  <pre><code>get selectedOptions() {
      return this.orderService.order.Products
          //.filter(opt =&gt; opt.checked)
          .map(opt =&gt; opt.value)
  }
  
  submitorder(form: NgForm) {
      var selection = this.selectedOptions;
  
      [post order here]
  }
  </code></pre>
  
  <p>but selectedOptions comes empty.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is the correct code for <code>selectedOptions()</code> method (note <code>opt.Id</code> not <code>opt.value</code> as above):</p>
  
  <pre><code>get selectedOptions() {
      return this.orderService.order.Products
          //.filter(opt =&gt; opt.checked)
          .map(opt =&gt; opt.Id)
  }
  </code></pre>
  
  <p>But the main question remains - how to get checked options?</p>