New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling platformBrowserDynamic a second time silently ignores extraProviders #25358
Comments
Source is at angular/packages/core/src/application_ref.ts Line 104 in c95437f
I'm willing to contribute, I'm just not sure what the desired behavior is. |
You can only have one platform injector. So in a way this works as intended. But an error would be useful. PR with error would be accepted. |
The idea was that the platform would hold singletons which have resources which are singletons on the browser such as Location URL. You can only have one of those. |
@mhevery But user can still override The only valid platform internal provider I can see is |
As I said "idea was" but I think there are simpler ways of getting there. Problem is that if you bootstrap two apps in a single page (rare but possible) than each app would bring its own going forward we are thinking of ways to remove it.... |
I did find a hacky workaround for the problem. Just swap the injector: const extraProviders = [
{
provide: 'myValue',
useValue: 'something',
}
]
const platform = platformBrowserDynamic()
;(platform as any)._injector = Injector.create({
providers: extraProviders,
parent: platform.injector,
})
platform.bootstrapModule(MyModule) Unfortunately this breaks AOT compilation because of angular/angular-cli#8880 |
I'm submitting a...
Current behavior
Both applications are bootstrapped but
'myValue'
is not available toModuleTwo
.You wouldn't write code like this in a single file but it may happen that independent code both calls
platformBrowserDynamic()
.Expected behavior
Either
extraProviders
available to the bootstrapped moduleWhat is the motivation / use case for changing the behavior?
The issue is hard to debug. Existing code can be broken by newly added independent code if that new code calls
platformBrowserDynamic()
earlier.Environment
Angular version: 6.1.1
Browser: not browser-specific
The text was updated successfully, but these errors were encountered: