I'm working on an angular 2 prototype component. I have two select controls that have the same options. In the second select element (destination) I would like to disable or remove the option that was selected in the first select element (origin). (Incidentally, any idea why the first selected option is displaying?)
Here is the plunkr
//our root app component
import {Component} from '@angular/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass} from '@angular/common';
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>{{name}}</h2>
<select id="trip_origin" [(ngModel)]="origin"
class="start" (change)="onChange($event)">
<option disabled selected >Select a shipping origination</option>
<option *ngFor="let item of items" [ngValue]="item"> {{item.name}} - {{item.loc}}</option>
</select>
<div>selected: {{origin | json}}</div>
<hr>
<select id="trip_destination" name="destination" [(ngModel)]="destination">
<option *ngFor="let item of items" [ngValue]="item">{{item.name}} - {{item.loc}}</option>
</select>
<div>selected: {{destination | json}}</div>
</div>
<h2>Destination -- {{destination.loc}}</h2>
<h2>Origin -- {{origin.loc}}</h2>
`,
directives: []
})
export class App {
public items:object[] = [
{"loc":"HOU","name":"Houston"},
{"loc":"DAL","name":"Dallas"},
{"loc":"SAT","name":"San Antonion"}
];
constructor() {
this.origin={};
this.name = 'Test Select Control'
this.destination = this.items[1]
}
onChange($event){
console.log($event)
}
}