2017-09-28 2 views
1

단위 테스트 각도 CLI를 실행하면 다음 오류가 발생합니다. 양식에 다음 오류가 있습니다.실패 : 템플릿 구문 분석 오류 : 각도 2

Failed: Template parse errors: 
There is no directive with "exportAs" set to "ngForm" ("<form [ERROR ->]#userForm = "ngForm" (ngSubmit)="onSubmit(userForm.value)"> 
    <div class="form-group"> 
     <label for="e") 

HTML 양식

<form #userForm = "ngForm" (ngSubmit)="onSubmit(userForm.value)"> 
<div class="form-group"> 
     <label for="exampleInputCountry">Country</label> 
     <input class="form-control" id="country" placeholder="Country" ng name="country" ngModel> 
    </div> 
    <button type="submit" class="btn btn-primary">Submit</button> 
</form> 

app.module.ts

@NgModule({ 
    declarations: [ 
    AppComponent, 
    [...] 
    ], 
    imports: [ 
    FormsModule, 
    [...] 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 

답변

2
당신은 당신의 테스트 모듈에 FormsModule를 가져와야합니다

TestBed.configureTestingModule({ 
    ..., 
    imports: [ 
    FormsModule, 
    ], 
}) 
관련 문제