[FR] APP_BASE_HREF useFactory Promise Support
See original GitHub issueI’m submitting a…
[x] Feature request
Current behavior
APP_BASE_HREF
useFactory
doesn’t support promises, only values.
Expected behavior
APP_BASE_HREF
useFactory
supports both values and promises.
What is the motivation / use case for changing the behavior?
In my application I need to set APP_BASE_HREF
asynchronously. Unfortunately, APP_BASE_HREF
useFactory
doesn’t support promises. So, I tried this approach with APP_INITIALIZER
, but failed as well as OP, because it seems like if you do AJAX requests in APP_INITIALIZER
useFactory
, you should setup APP_BASE_HREF
first.
APP_INITIALIZER
supports promises in useFactory
, so it would be very useful if APP_BASE_HREF
supports them too.
Environment
Angular version: 6.0.0
Browser:
- [x] Chrome (desktop) version 69
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Angular 2 Set APP_BASE_HREF with a value from a Promise ...
I tried your solution. The problem is, that at the time { provide: APP_BASE_HREF, useFactory: (config) => config.
Read more >APP_BASE_HREF - Angular
The following example shows how to use this token to configure the root app injector with a base href value, so that the...
Read more >How To Handle Async Providers in Angular
We add a factory function which takes our service as the first parameter. In it, we return a function returning a promise —...
Read more >A minimalist ASPNETZERO Angular client #11164
Go to ./nswag and run ./resfresh.bat (ASPNETZERO Core Services must be up and running). This creates ./src/shared/service-proxies ...
Read more >Angular: Use APP_INITIALIZER DI Token with Observables ...
How APP_INITIALIZER can be used with Observables and Promises. ... useFactory contains the factory function which will be the value for this DI...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s another use case, when supporting promises in
APP_BASE_HREF
might be useful: You need to set app base href dynamically using external configuration.APP_INITIALIZER
(download config file via http call)useFactory
ofAPP_BASE_HREF
provider you need to wait for this call to finish to get config. And since you can only use value there, it’s not possible (correct me if I’m wrong). Seems like currently the only way to do so, is to move config loading intomain.ts
file, and bootstrap application only after all configs are loaded and pass config in extra providers like so (again correct me if I’m wrong) :Which seems like a hack, especially when APP_INITIALIZER is used specifically for app initialization, but you can’t use it in this particular case.
The same issue is described here: https://stackoverflow.com/questions/46190280/angular-2-set-app-base-href-with-a-value-from-a-promise-observable
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular’s feature request process in our documentation.