Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在角组件的单元测试中提供ControlContainer?_Angular_Typescript_Unit Testing_Angular Test_Ts Jest - Fatal编程技术网

Angular 如何在角组件的单元测试中提供ControlContainer?

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的提供程

根据标题,如何在角度单元测试中提供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 } ]
我运气不好,但如果有人能在这里透露一些信息;我将不胜感激。

我能够从这篇文章中得出解决方案:

我最后做的是:

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。仍然不起作用。