2017-09-28 17 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, 
    ], 
}) 
関連する問題