Angular 4 form select可显示默认值
application.customer和customer都是客户对象的类型。在组件中填充应用程序时,不会设置默认值。其他文本输入字段,如application.vehicle\u make,可以在没有任何问题的情况下加载。有人知道为什么不选择应用程序的默认值吗?我正在使用最新的angular 5。将其与您的特定用途Id绑定 {{customer.id}{{customer.first{u name}{{customer.last{u name}} 现在[ngValue]转向[value]很可能没有一个客户的客户与application.customer相等。如果要选择默认值,则需要将该属性添加到以下项目之一:Angular 4 form select可显示默认值,angular,select,default,angular5,angular4-forms,Angular,Select,Default,Angular5,Angular4 Forms,application.customer和customer都是客户对象的类型。在组件中填充应用程序时,不会设置默认值。其他文本输入字段,如application.vehicle\u make,可以在没有任何问题的情况下加载。有人知道为什么不选择应用程序的默认值吗?我正在使用最新的angular 5。将其与您的特定用途Id绑定 {{customer.id}{{customer.first{u name}{{customer.last{u name}} 现在[ngValue]转向[value]很
`<select class="form-control" id="customer" required [(ngModel)]="application.customer" name="customer" #customer="ngModel">
<option *ngFor="let customer of customers" [ngValue]="customer">
{{customer.id}} {{customer.first_name}} {{customer.last_name}}</option>
</select>`
这将选择客户阵列中的第一项。您还可以使用let i=索引;在*ngFor中选择某个索引,甚至使用let last=last。这会将application.customer设置为客户的选定客户
<option *ngFor="let customer of customers; let first = first;" [ngValue]="customer" selected="first">
{{customer.id}} {{customer.first_name}} {{customer.last_name}}</option>