Angular 如何在角组件的单元测试中提供ControlContainer?
根据标题,如何在角度单元测试中提供ControlContainer 以下是产生的错误: NullInjectorError:StaticInjectorErrorDynamicTestModule[ChildFormComponent->ControlContainer]: StaticInjectorErrorPlatform:core[ChildFormComponent->ControlContainer]: NullInjectorError:没有ControlContainer的提供程序! 我尝试提供ControlContainer: beforeach=>{ const parentFixture=TestBed.createComponentParentFormComponent; 常量parentComponent=parentFixture.componentInstance; parentComponent.initForm; fixture=TestBed.createComponentChildFormComponent; 组件=fixture.componentInstance; 夹具。检测变化; }; 我见过其他使用以下方法的解决方案: 声明:[ …我的声明 ], 进口:[ …我的朋友 ], 供应商:[ { 提供:控制容器, useValue:MyFormGroupDirective } ]Angular 如何在角组件的单元测试中提供ControlContainer?,angular,typescript,unit-testing,angular-test,ts-jest,Angular,Typescript,Unit Testing,Angular Test,Ts Jest,根据标题,如何在角度单元测试中提供ControlContainer 以下是产生的错误: NullInjectorError:StaticInjectorErrorDynamicTestModule[ChildFormComponent->ControlContainer]: StaticInjectorErrorPlatform:core[ChildFormComponent->ControlContainer]: NullInjectorError:没有ControlContainer的提供程
我运气不好,但如果有人能在这里透露一些信息;我将不胜感激。我能够从这篇文章中得出解决方案: 我最后做的是: let组件:MyChildComponent; let夹具:组件夹具 设fg:FormGroup; let fgd:FormGroupDirective; beforeach=>{ TestBed.configureTestingModule{ 声明:[我的声明], 导入:[…我的_导入], 供应商:[ {提供:ControlContainer,useValue:fgd} ] }; }; beforeach=>{ const parentFixture=TestBed.createComponentMyParentComponent; 常量parentComponent=parentFixture.componentInstance; fg=parentComponent.form; fgd=新FormGroupDirective[],[]; fgd.form=fg; const childFixture=TestBed.createComponentMyChildComponent; const childComponent=childFixture.componentInstance; childFixture.detecttchanges; };
我想做的是将初始化的父窗体组附加到子窗体。是否包含相关的窗体模块?@jornsharpe是,已导入ReactiveFormsModule和FormsModule。仍然不起作用。