我有一个与客户打交道的Angular 2应用程序和一个弹簧休息后端.客户对象有一个客户类型,也是一个对象,我在客户表单上下拉工作,以便将对象存储为值,但我无法弄清楚如何选择正确的客户类型现有客户已加载到表单中.
<select class="form-control" required [(ngModel)]="customer.customerType" > <option *ngFor="let ct of customerTypes" [ngValue]="ct">{{ct.customerType}}</option> </select>
在上面的代码段中,如果客户已有客户类型,则下拉列表将不会选择任何值.我记得使用ngOptions解决了angular1的相同问题:
<select ng-model="customer.customerType" ng-options="customerType.customerType for customerType in customerTypes track by customerType.customerType" > </select>
所以,我的问题是,如何复制Angular1在Angular 2中解决这个问题的方式
我有同样的问题,我这样解决了:
<select class="form-control" required [(ngModel)]="customer.customerType" > <option *ngFor="let ct of customerTypes" [ngValue]="ct" [attr.selected]="customer.customerType.customerType==ct.customerType ? true : null" >{{ct.customerType}}</option> </select>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。