【发布时间】:2016-08-11 21:56:30
【问题描述】:
这是我的选择代码:
<select class="form-control" [(ngModel)]="selectedPrototypeSelector" (ngModelChange)="onPrototypeChange()">
<option *ngFor="#p of prototypes" [value]="p.selector">
{{ p.selectorName }}
</option>
</select>
如何为这个 select option 设置标准开始值我想我必须设置这个变量:
selectedPrototypeSelector: string;
对此:selectedPrototypeSelector: string = "Test";
但是"Test" 没有在选择框中首先显示开始值为空,我该如何设置例如:选择您的选项。
这里是PLUNKER,
正如你所见,当我设置值 p.selector 时,选择框是空的,第二次选择时我设置 constraint 的值也是如此:
<select class="form-control" [(ngModel)]="expression.constraint">
<option *ngFor="#constraint of prototype.constraints" [value]="constraint">
{{ constraint }}
</option>
</select>
我想将每个选择框的开始值设置为静态string = "Select an option";
【问题讨论】:
-
默认值应该是多少?它从何而来?组件类的属性或一些静态字符串值?
-
@GünterZöchbauer 这只是一个静态字符串值我编辑了我的问题
-
我更新了答案。
标签: typescript angular