问题
ng test
shows the below error but it works as expected in reality.
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.
I think it's mainly because of adding [ngModelOptions]="{standalone: true}"
in a custom tag.
回答1:
Did you add reference to "FormsModule" in your TestBed module?
import { FormsModule } from '@angular/forms';
TestBed.configureTestingModule({
imports: [ FormsModule ]
})
.compileComponents();
来源:https://stackoverflow.com/questions/42002079/angular2-testcase-shows-no-provider-for-ngcontrol