简体   繁体   English

选择Angular 4时为空默认选项

[英]Empty default option on select Angular 4

What I'm trying to do is Angular to get the value from an variable and put it on the first option, while the others below will be static. 我想做的是Angular从变量获取值并将其放在第一个选项上,而下面的其他选项将是静态的。 Angular is getting the data but the first option is always blank. Angular正在获取数据,但第一个选项始终为空。

HTML HTML

<select [(ngModel)]="sub_planning">
<option value="data[0].value" >{{data[0].name}}</option>
<option *ngFor="let c of subdimension" [ngValue]="c.value">{{c.name}}</option>
</select>

TS TS

sub_planning = '0';
subdimension = [{'name': 'oneabc','value': 1 },
  {'name': 'twoabc','value': 2}];

I found some answers on the internet but it's on Angular 2 and it does't seems to work for Angular 4 我在互联网上找到了一些答案,但它在Angular 2上使用,但似乎不适用于Angular 4

Because of invalid datatypes, 由于数据类型无效,

sub_planning = 1

Note: Type of number. 注意:数字类型。

LIVE DEMO 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM