NetanelBasal
11/27/2016 - 12:41 PM

checkbox-multiple.td.ts

@Component({
  selector: 'my-app',
  template: `
    <form #f="ngForm">
      <div *ngFor="let category of categories;">
        <input type="checkbox" 
        [ngModelOptions]="{standalone: true}"
        [(ngModel)]="category.selected"/> {{category.title}}
      </div>
      <button (click)="getSelectedCategories()">Get selected categories</button>
    </form>
  `,
})
export class App {
  categories = [{title: 'Food', selected: false}, {title: 'Cars', selected: true}, {title: 'Shopping', selected: false}];

  getSelectedCategories() {
    const selected = this.categories.filter(c => c.selected);
    console.log(selected);
  }
  
}