angular: Unable to use singleton platform injector service shared by all applications on the page
🐞 bug report
Affected Package
Using angular 9.0.0 release version.Is this a regression?
NoDescription Unable to create the singleton service and use across multiple angular elements on the same page when it is decorated as providedIn:platform
Please see the below image which summarizes the whole flow;
🔬 Minimal Reproduction
1-Create an angular library project which only have one angular service which uses providedIn: ‘platform’. The service has two method getTitle and setTitle, which are just getter and setter for the service property named title. 2-Create a new angular element app and use the service created in step-1. Create a button(Set Title) in component and call the service’s setTile method by passing the value “Setting title from element1”. 3-Create another new angular element app and use the service created in step-1. Create a button (Get Title) in component and use the getTitle method of the service. 4-Create a new angular container app or in index.html which uses both angular elements created in step 2 & 3. And now press “Set Title” and then press “Get Title” buttons.
🔥 Exception or Error
No
Expectation: As per documentation, there should be a single instance of the service should exists but two separate instances of the service are created for each element. Pressing “Get Title” button should return “Setting title from element1” text, but it is returning blank.
Documentation Links: https://next.angular.io/api/core/Injectable
🌍 Your Environment
Angular Version:
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (8 by maintainers)
@flash-me very very thanks for your valuable suggestion We don’t want to intercept the webpack bundling / build process if it hurts the natural flow of angular/webpack and it seems there is no official way to achieve the work we listed above . We will definitely try this out with transformed object or making custom builder to achieve this. @robwormald @manfredsteyer @IgorMinar @StephenFluin any more suggestions .