ng test
显示以下错误,但实际上可以正常工作。
Error: Template parse errors:
No provider for NgControl ("
<div class="form-group">
<label class="control-label">Location</label>
[ERROR ->]<select class="selectpicker" *ngIf="locations" data-style="btn btn-primary btn-round" title="Select A"): VehicleFormComponent@27:4
No provider for NgControl (" <div class="form-group label-floating">
<label class="control-label">Is Available</label>
[ERROR ->]<md-slide-toggle [(ngModel)]="isAvailable" color="primary" [ngModelOptions]="{standalone: true}">
"): VehicleFormComponent@41:4 in src/test.ts (line 25739)
Expected undefined to be truthy.
我认为这主要是因为在自定义标记中添加[ngModelOptions]="{standalone: true}"
。
答案 0 :(得分:3)
您是否在TestBed模块中添加了对“FormsModule”的引用?
import { FormsModule } from '@angular/forms';
TestBed.configureTestingModule({
imports: [ FormsModule ]
})
.compileComponents();
答案 1 :(得分:2)
如果其他人来这里,也许这会有所帮助。我在构造函数中缺少可选的装饰器:
constructor(@Optional() @Self() public ngControl: NgControl) {}