以模板形式复制数据并选择选项不显示数据角度2

时间:2017-10-25 16:53:31

标签: javascript angular angular2-forms

我需要构建一个函数来复制表中的数据。这个想法是当选择一行并单击复制按钮时,将复制所选行。我能够复制组件中的数据,并将其推送到数组列表,输入字段工作正常。但是选择字段没有显示数据。我是Angular 2的新手,感谢任何帮助。 这是我的代码,它是一个非常复杂的表。

   <button class="btn btn-outline-primary btn-sm"                  
           (click)="copySelectedService()">Copy Service</button>

   <table class="table table-sm table-bordered" id="service">
      <tr *ngFor="let s of serviceList  let i = index">
       <td>
         <div>
         <select class="custom-select service" [ngModel]="s?.srvc_nm" 
           name="srvc_nm{{i}}" (ngModelChange)="s?.srvc_nm?
               s.prog_srvc_nm=$event:null">
                    <option></option>
                    <option *ngFor="let a of dropdownLists['srvc']" 
                       [ngValue]="a.description" >{{a.description}}</option>
         </select>
        </div>
         <div class="cell top-cell">
           <input type="text" class="form-control" name="channel_nb{{i}}" 
               [ngModel]="s?.channel_nb" (ngModelChange)="s?.channel_nb? 
               .channel_nb=$event:null">
         </div>
       </td>
      </tr>
     </table>

Component.ts

    serviceList: any[];

    copySelectedService() {
       const cloned = Object.assign({}, this.serviceList[this.index]);    
       this.serviceList.push(cloned);
    }

服务模式:

        export class Service {
           srvc_nm?: string;
           channel_nb?: string;
             ....

           constructor () {
              this.prog_srvc_nm = '';
              this.channel_nb = '';
           ....
          }
        }  

选择选项我做错了吗?

0 个答案:

没有答案