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