저는 각도 2 프로토 타입 구성 요소를 사용하고 있습니다. 동일한 옵션을 가진 두 개의 선택 컨트롤이 있습니다. 두 번째 select 요소 (대상)에서 첫 번째 select 요소 (origin)에서 선택한 옵션을 비활성화하거나 제거하고 싶습니다.angular2 보조 선택 요소에서 선택 옵션을 제거하거나 사용 중지합니다.
<select id="trip_destination" name="destination" [(ngModel)]="destination">
<option [disabled]="item === origin" *ngFor="let item of items" [ngValue]="item">{{item.name}} - {{item.loc}}</option>
^^^^^^^^^^
</select>
: (? 덧붙여, 어떤 생각이 왜 처음 선택한 옵션이 표시됩니다) 여기
는 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)
}
}
감사합니다 줄 예상대로 그 다음이 표시 될
을 가지고수와의 ctor를 변경하려면이 옵션을 변경할 수 있습니다! 우수 답변 .. – daddyschmack