[英]Failed: Template parse errors: Angular 2
I'm getting the following error once running Unit-test angular CLI. 运行单元测试角度CLI时出现以下错误。 The following error is on a form.
表单上出现以下错误。
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")
The html form 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 app.module.ts
@NgModule({
declarations: [
AppComponent,
[...]
],
imports: [
FormsModule,
[...]
],
providers: [],
bootstrap: [AppComponent]
})
You should import FormsModule
to your testing module 您应该将
FormsModule
导入到测试模块
TestBed.configureTestingModule({
...,
imports: [
FormsModule,
],
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.