加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2选择了包含对象的选项

发布时间:2020-12-17 10:17:04 所属栏目:安全 来源:网络整理
导读:我有一个与客户打交道的Angular 2应用程序和一个弹簧休息后端.客户对象有一个客户类型,也是一个对象,我在客户表单上下拉工作,以便将对象存储为值,但我无法弄清楚如何选择正确的客户类型现有客户已加载到表单中. select class="form-control" required [(ngMo
我有一个与客户打交道的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>

感谢Günter Z?chbauer

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读