如果我在HTML中包含一个组件并通过DI注入它,为什么会出现StaticInjector错误?

问题描述 投票:0回答:1
我有一个使用ValidateSessionComponent的组件LoginFormComponent。我通过将LoginFormComponent的HTML包含在ValidateSessionComponent中来使用ValidateSessionComponent

到目前为止效果很好。然后,我决定通过LoginFormComponent]中的DI也包含对ValidateSessionComponent的引用

constructor(private loginForm2:LoginFormComponent,private helper:HelperService,private dialogService:DialogBoxService,private activatedRoute:ActivatedRoute, private router:Router, private userManagementService:UserManagementService) { }

这开始导致错误StaticInjectorError(DynamicTestModule)[ValidateSessionComponent -> LoginFormComponent]: 
  StaticInjectorError(Platform: core)[ValidateSessionComponent -> LoginFormComponent]: 
    NullInjectorError: No provider for LoginFormComponent!

为什么我开始出现错误?

我有一个使用LoginFormComponent的ValidateSessionComponent组件。我通过在ValidateSessionComponent的HTML中包含LoginFormComponent来在ValidateSessionComponent中使用它。这有效...

angular angular6
1个回答
1
投票
因为DI仅适用于提供者。

组件不是提供者。

© www.soinside.com 2019 - 2024. All rights reserved.