2017-08-10 61 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" 
相关问题