Html 带有选择列表的ngModel
我在从select元素输出值时遇到问题Html 带有选择列表的ngModel,html,angularjs,typescript,drop-down-menu,angular-ngmodel,Html,Angularjs,Typescript,Drop Down Menu,Angular Ngmodel,我在从select元素输出值时遇到问题 <select ([ngModel])="office_hour_start" name="office_hour_start"> <option *ngFor="let time of times" value="{{time.i}}"> {{ time.i }} </option> </select> 此设置在此处对我有效: <select [(ngMo
<select
([ngModel])="office_hour_start"
name="office_hour_start">
<option
*ngFor="let time of times"
value="{{time.i}}">
{{ time.i }}
</option>
</select>
此设置在此处对我有效:
<select
[(ngModel)]="employee_id"
name="employee_id"
class="form-control">
<option
*ngFor="let employee of employees"
value="{{employee.id}}">
{{ employee.name }}
</option>
</select>
希望这有帮助,请使用ng选项而不是ng for在对您有效的设置上,另一个建议是:
// When using an ngModel, an event emitter () should be inside the input [] always
// Though there is an instance where you can use it separately [ngModel] for Input (ngModelChange) for event emitter
<select [(ngModel)]="employee_id"
name="employee_id"
class="form-control">
<option *ngFor="let employee of employees"
value="{{employee.id}}"> // use [value]="employee.id" if you're assigning a dynamic value
{{ employee.name }}
</option>
</select>
对于办公时间的例子来说,启动是它的模式。你曾经
[ngModel]=office\u hour\u start而不是[ngModel]=office\u hour\u start将括号放在括号内[]是解决问题的方法
为您的参考创建了一个似乎不起作用:/n以前从未使用过该样式,因此需要一段时间进行故障排除。请参阅以了解正确的使用方法。我只希望选择该值。我正在进行一个api调用,它使用这个值作为URL的一部分。办公室里什么都没有。开始吧。这太可笑了。我让该员工选择了以前的工作作为参考。@Prozak创建了一个Stackblitz演示供您参考。更新了我的评论和链接:-办公时间开始的理由是它的NGF模式。你用了[ngModel]=office\u hour\u start而不是[ngModel]=office\u hour\u start把括号放在括号内[]是解决这个问题的方法。非常感谢你,你让我免于抓狂。括号就是问题所在。@Prozak如果这个解决方案对你有帮助,介意你投票并将答案标记为接受答案吗?那将是一个很大的帮助。非常感谢你:
// When using an ngModel, an event emitter () should be inside the input [] always
// Though there is an instance where you can use it separately [ngModel] for Input (ngModelChange) for event emitter
<select [(ngModel)]="employee_id"
name="employee_id"
class="form-control">
<option *ngFor="let employee of employees"
value="{{employee.id}}"> // use [value]="employee.id" if you're assigning a dynamic value
{{ employee.name }}
</option>
</select>