angular4 select 绑定(ngModel)对象

<h1>My Application</h1>
<select [(ngModel)]="selectedValue">
  <option *ngFor="let c of countries" [ngValue]="c">{{c.name}}</option>
</select>

ts:

countries:Array<Object> = [
    {num: 0, name: "AA"},
    {num: 1, name: "BB"}
    ];
  c = this.countries[0];

示例代码

注意: 你可以用 [ngValue]="c"替换[ngValue]="c.id" 当c是一个对象

[value]="..." 只支持字符串
[ngValue]="..." 支持任何类型

如何value是对象,ngModel绑定的值也需要是相同的对象!

参考https://github.com/angular/angular/issues/13268

levels   ['levəlz]   详细 X
基本翻译
n. 水平,标准(level复数形式);色阶调整;控制色阶
v. 拉平,变平(level的第三人称单数形式)
网络释义
Levels: 色阶
Auto Levels: 自动色阶
Isolation levels: 隔离级别

猜你喜欢

转载自www.cnblogs.com/wangzhichao/p/10454799.html
今日推荐