我想在单击添加按钮时添加一个“ div”字段。我该怎么做?

时间:2019-02-08 06:13:59

标签: html5 angular5 angular6 angular7

我已使用此解决方案添加字段:-Add DOM element on Button click with Angular 2+

但是我无法实现所需的重用。

HTML:-

<div class="row" *ngFor="let fields of addFields">
    <div class="col-sm-2">
      <label>Choose Category</label>
      <select (change)="getVal($event)">
        <option value="0">--</option>
        <option *ngFor="let service of services" value="{{service._id._id}}">{{service._id.name}}</option>
      </select>
    </div>
    <div class="col-sm-2">
      <label>Choose Service</label>
      <select (change)="getServiceVal($event)">
        <option value="0">--</option>
        <option *ngFor="let ser of servicess" value="{{ser.name}}">{{ser.name}}</option>
      </select>
    </div>
  </div>
  <input type="button" value="Add Service" (click)="add()">

TS:-

 addFields = ['fields1']
  fieldsNumber = 1;


  add(){
    this.fieldsNumber++;
    this.addFields.push("field"+this.fieldsNumber);
   }

0 个答案:

没有答案