2017-02-02 24 views
0

ng test顯示下面的錯誤,但它在現實中按預期工作。Angular2 testcase shows顯示沒有NgControl的供應商

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"): [email protected]: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}"> 
     "): [email protected]:4 in src/test.ts (line 25739) 
    Expected undefined to be truthy. 

我認爲這主要是因爲在自定義標籤中添加了[ngModelOptions]="{standalone: true}"

+0

您是否在TestBed模塊中添加了對「FormsModule」的引用? – VadimB

+0

真棒,謝謝) – VadimB

回答

2

您是否在TestBed模塊中添加了對「FormsModule」的引用?

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

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

你能重現這個錯誤嗎?PhantomJS 2.1.1(Linux 0.0.0):執行65(1失敗)(0秒/1.296秒)中的第39個 PhantomJS 2.1.1(Linux 0.0.0 )VehicleFormComponent應該創建失敗 \t得到 \t LocationsService @的WebPack:///src/app/shared/services/locations.service.ts:9:4173 < - SRC/test.ts:53695:4196 \t getInternal' –

+0

是的,我有這個錯誤。嘗試在你的TestBed導入中添加'RouterTestingModule'。從「@ angular/router/testing」中的'import {RouterTestingModule}導入;'。讓我知道它是否有幫助。 – VadimB

+0

它不會起作用。 –