我已使用此解决方案添加字段:-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);
}