运行单元测试角度CLI后,我收到以下错误。表单上存在以下错误。
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]
})
答案 0 :(得分:2)
您应该将FormsModule
导入测试模块
TestBed.configureTestingModule({
...,
imports: [
FormsModule,
],
})