首页 > 解决方案 > 如何在 ngModel 中获取 ngx-chips 值?

问题描述

我已经在电子邮件地址字段中实现了 ngx-chips。它运作良好。但是,当我在 component.ts 中输出值时,我只得到第一个芯片的值。如何获得所有筹码的价值?

如果我在 html 中有 a@xyz.com 和 b@xyz.com,则 ngModel 中只有 a@xyz.com。

组件.html

<div class="form-row">
    <div class="required form-group col-md-12 col-sm-12 col-xs-12" >
      <label class="control-label" for="email.emailCc">CC:</label>
       <tag-input [ngModel]="[email.emailCc]"  theme='bootstrap'>
        <tag-input-dropdown [autocompleteObservable]="items" [showDropdownIfEmpty]="true" [dynamicUpdate]="false"></tag-input-dropdown>
        </tag-input>
    </div>
 </div>

 <div class="form-group col-md-12 col-sm-12 col-xs-12">
     <button (click)="sendEmail()" class="btn btn-lg btn-primary btn-block">Send</button>
 </div>

组件.ts

 public items = (text: string): Observable<Response> => {
   return this.sendEmailService.getEmailList(text);
 };

sendEmail(){
   console.log("email cc:"+this.email.emailCc);
 }

输出

email cc:a@xyz.com

标签: angular7ngx-chips

解决方案


推荐阅读