2017-08-10 58 views
0

這裏即時使用Anular2 FormGroup在我的模態模板即使是即時通訊獲取此錯誤。 這是我的表格然後組爲什麼我收到提示下面是我的總碼formGroup需要一個FormGroup實例。請通過一個。在Angular2中獲取錯誤

<div class="modal-header"> 
    <h4 class="modal-title pull-left">{{title}}</h4> 
    <button type="button" class="close pull-right" aria-label="Close" (click)="bsModalRef.hide()"> 
     <span aria-hidden="true">&times;</span> 
    </button> 
</div> 
<div class="modal-body"> 
     <form class="form-horizontal" novalidate [formGroup]="EmployeeForm"> 
      <fieldset> 
       <div class="form-group" [ngClass]="{'has-error': (EmployeeForm.get('EmpName').touched || 
                EmployeeForm.get('EmpName').dirty) && 
                !EmployeeForm.get('EmpName').valid }"> 
        <label for="name">Name</label> 
        <input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="EmpName" /> 
        <span class="help-block" *ngIf="(EmployeeForm.get('EmpName').touched || 
                 EmployeeForm.get('EmpName').dirty) && 
                 EmployeeForm.get('EmpName').errors"> 
         <span *ngIf="EmployeeForm.get('EmpName').errors.required"> 
          Please enter your first name. 
         </span> 
         <span *ngIf="EmployeeForm.get('EmpName').errors.minlength || EmployeeForm.get('EmpName').errors.maxlength || 
         EmployeeForm.get('EmpName').pattern"> 
          The first name must be longer than A3 and max5 characters. 
         </span> 
        </span> 
       </div> 

Componet.ts

EmployeeForm: FormGroup; 

回答

1

您需要添加一個ngIf條件檢查如果FormGroup的值爲

*ngIf="EmployeeForm" 
相關問題