在终端中运行ng test
时出现问题。错误是
"键入' FormGroup'不能分配给' FormArray'
。
属性类型'controls'
不兼容。
"
我该如何解决这个问题? ------------------------------------------ /这是一个提供我的课程一个问题-----------------
这是代码
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SharedModule } from '../../../../shared/shared.module';
import { FormGroup, Validators, FormControl, FormArray } from '@angular/forms';
import { StepAvailabilityComponent } from './step-availability.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
describe('StepAvailabilityComponent', () => {
let component: StepAvailabilityComponent;
let fixture: ComponentFixture<StepAvailabilityComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StepAvailabilityComponent ],
imports: [SharedModule, FormsModule, ReactiveFormsModule]
})
.compileComponents();
}));enter code here
beforeEach(() => {
fixture = TestBed.createComponent(StepAvailabilityComponent);
component = fixture.componentInstance;
component.fg = new FormGroup({operatingDays: new FormArray(
[
new FormGroup({
enabled: new FormControl(false),
localName: new FormControl('mandag'),
}),
]
)});
fixture.detectChanges();
});