Service provided in Wrapped Component but can´t be resolved, if wrappercomponent is used in template #43041
Labels
area: core
Issues related to the framework runtime
core: di
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Milestone
Which @angular/* package(s) are the source of the bug?
common
Is this a regression?
No
Description
In principal the Bug can be described the easiest in the following way:
The minimal reproduction of the bug contains of 3 components:
HostParentComponent: Does not provide a flowerservice. In its template is the HostComponent and the content is forwarded to the content of the HostComponent via
<ng-content></ng-content>
. Template =<app-host><ng-content></ng-content></app-host>
HostComponent: Provides the flowerservice. In its template the emoji property of the service is shown and the ng-content is displayed afterwards. Template =
<p>Flower emoji: {{flower.emoji}}</p><ng-content></ng-content>
HostChildComponent: Does not provide a flowerservice, but tries to resolve the provided flowerservice and displays the emoji in the template. Template =
<p>Flower emoji: {{flower ? flower.emoji : 'not resolvable as service is null !!!'}}</p>
Now the following two cases pointed out:
1.) Use of the HostParentComponent with the HostChildComponent as Content:
Template:
<app-host-parent> <app-host-child> </app-host-child> </app-host-parent>
Expected behaviour: As app-host-parent includes the HostComponent in its template, which provides the flowerservice, also the HostChildComponent should have access to this service.
Actual behaviour: The HostChildComponent can´t resolve the service !
2.) Use of the HostComponent with the HostChildComponent as Content:
Template:
<app-host> <app-host-child></app-host-child> </app-host>
Expected = Actual bahaviour: As the HostComponent provides the flowerservice, also the HostChildComponent has access to this instance of the service.
The attached figure illustrates the behavior just described.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-omarrt?file=src/app/host-child/host-child.component.ts
Please provide the exception or error you saw
Please provide the environment you discovered this bug in
Anything else?
In the link for the minimal reproduction of the Bug, the error has been avoided as an
@Optional
has been written for the serviceinjection. To show the error again, just remove the@Optional
in the HostChildComponent.The text was updated successfully, but these errors were encountered: