NetanelBasal
11/27/2016 - 10:54 AM

selectbox-multiple.td.ts

@Component({
  template: `
    <form #f="ngForm">
      <select name="state" [ngModel]="activeStates" multiple>
        <option *ngFor="let state of states" [ngValue]="state">
          {{ state.name }}
        </option>
      </select>
    </form>
    
     <p>Form value: {{ f.value | json }}</p>
     <!-- value: {activeStates: [{name: 'California', code: 'CA'}] } -->
  `,
})
export class App {
  
  states = [
    {name: 'Arizona', code: 'AZ'},
    {name: 'California', code: 'CA'},
    {name: 'Colorado', code: 'CO'}
  ];
  
  activeStates = [this.states[1]];
}