1
@Component({
selector: 'filter',
template: "<select [(ngModel)]="filterState" (change)="selected()">
<option value="">All</option>
<option *ngFor="let s of states " [ngValue]="s">{{ s.label}}</option>
</select>",
});
export class FilterComponent {
private states = [
{
value: 'active',
label: 'Active',
},
{
value: 'done',
label: 'Done',
},
{
value: 'removed',
label: 'REMOVED',
}
];
private filterState = '';
selected() :void {
//this.filterState is still the initiated value
}
}
在上述情況下,「全部」選項不顯示,並且每當更改選項ngModel它都不會更新。angular2選擇選項選擇問題
嘗試使用值而不是ngValue,並嘗試使用私有filterState = 0;但同樣的情況,在這裏
仍然是同樣的問題 – Niyaz
你能提供一個允許重現的Plunker嗎? –
https://plnkr.co/edit/9ZWpccOyNklxHFL92PT8 – Niyaz