[英]Can't bind to 'ngModel' since it isn't a known property of 'select'
Using Angular 2.4.0 (current setup with Angular CLI v1.0.0-rc.0) Created components, classes and services, default specs created. 使用Angular 2.4.0(使用Angular CLI v1.0.0-rc.0的当前设置)创建的组件,类和服务,以及默认规范。 ng test worked fine. ng测试效果很好。
Added an input with [(ngModel)] in it, and now am getting the message above when I run "ng test" 添加了一个带有[(ngModel)]的输入,现在当我运行“ ng test”时收到上面的消息
app.module.ts app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
AbsenceComponent,
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
absence.component.ts missing.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-absence',
templateUrl: './absence.component.html',
styleUrls: ['./absence.component.css']
})
export class AbsenceComponent implements OnInit {
selectedValue = null;
constructor() { }
ngOnInit() {
}
}
absence.component.html missing.component.html
<select [(ngModel)]="selectedValue">
<option value="0">Value 0</option>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>
absence.component.spec.ts (default created by "ng g component absence") missing.component.spec.ts(默认由“ ng g组件缺失”创建)
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AbsenceComponent } from './absence.component';
describe('AbsenceComponent', () => {
let component: AbsenceComponent;
let fixture: ComponentFixture<AbsenceComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AbsenceComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AbsenceComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Try below, 试试下面,
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ FormsModule ],
// you need to import, provide anything you need in the component
// so that they can be used\injected in the component for test.
declarations: [ AbsenceComponent ]
})
.compileComponents();
}));
Read more about it here . 在此处了解更多信息。
Hope this helps!! 希望这可以帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.