Angular2 testcase shows No provider for NgControl

£可爱£侵袭症+ 提交于 2019-12-12 04:24:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!