Wie man Formularfelder in Angular 2 dynamisch hinzufügt und entfernt

Ich versuche, Eingabefelder dynamisch hinzuzufügen, während der Benutzer auf die Schaltfläche zum Hinzufügen klickt. Wenn der Benutzer auf das Entfernen der Formularfelder klickt, muss für jedes Formularfeld eine Schaltfläche zum Entfernen vorhanden sein. Dies muss mithilfe von Angular 2 erreicht werden. Da ich neu in Angular 2 bin, hilf mir bitte, es zu vervollständige

Was ich versucht habe

Ich habe eine Reihe von Feldern erstellt (3 Auswahlfelder und 1 Textfeld), eine Schaltfläche mit dem Namen "Felder hinzufügen" erstellt, aber ich habe es in Winkel 1.x ausprobiert, es funktioniert einwandfrei, aber in Winkel 2 weiß ich nicht, wie ich es vervollständigen soll es, das istVerknüpfun meiner vollen Arbeit

app/app.component.ts
 import {
    Component
  }
from '@angular/core';
  @Component({
    selector: 'my-app',
    template: `
    <h1>{{title}}</h1>
    <div class="container">
    <button class="btn btn-success bt-sm">add</button>
    <form role="form" calss="form-inline">
    <div class="form-group col-xs-3">
    <label>Select State:</label>
    <select class="form-control" [(ngModel)]="rules.State" id="sel1">
            <option>State1</option>
            <option>State2</option>
            <option>State3</option>
            <option>State4</option>
</select>
     </div>
    <div class="form-group col-xs-3">
<label>Rule:</label>
     <input type="text" data-toggle="modal" data-target="#myModal" class="form-                   control">
    </div>
<div class="form-group col-xs-3">
<label>Pass State :</label>
    <select class="form-control" [(ngModel)]="rules.pass">
    <option>State1</option>
    <option>State2</option>
    <option>State3</option>
    <option>State4</option>
</select>
 </div>
 <div class="form-group col-xs-3">
    <label>Fail State:</label>
        <select class="form-control" [(ngModel)]="rules.fail">
        <option>State1</option>
        <option>State2</option>
        <option>State3</option>
     <option>State4</option>
     </select>
         </div>
    </form>
     </div>
 <div class="modal fade" id="myModal" role="dialog">
      <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                     <button type="button" class="close" data-dismiss="modal">&times    </button>
                    <h4 class="modal-title">Rules Configuration</h4>
                </div>
                <div class="modal-body">
                 <p>Rules</p>
                </div>
                 <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-  dismiss="modal">Close</button>
                </div>
             </div>

                </div>
                 </div>
`
    })
    export class AppComponent {
            title = 'Rule Engine Demo';
          rules: Rules = {
                  State: '',
                  pass: '',
                 fail: ''
                };

Antworten auf die Frage(2)

Ihre Antwort auf die Frage