Angular2测试用例显示NgControl没有提供程序 [英] Angular2 testcase shows No provider for NgControl

查看:109
本文介绍了Angular2测试用例显示NgControl没有提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng test显示以下错误,但实际上可以正常工作.

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.

我认为这主要是因为在自定义标签中添加了[ngModelOptions]="{standalone: true}".

I think it's mainly because of adding [ngModelOptions]="{standalone: true}" in a custom tag.

推荐答案

您是否在TestBed模块中添加了对"FormsModule"的引用?

Did you add reference to "FormsModule" in your TestBed module?

import { FormsModule } from '@angular/forms';

TestBed.configureTestingModule({
  imports: [ FormsModule ]
})
.compileComponents();

这篇关于Angular2测试用例显示NgControl没有提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆