question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FR] APP_BASE_HREF useFactory Promise Support

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
VitaliParkcommented, Jan 22, 2020

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.

  • In order to get this external configuration you can use APP_INITIALIZER (download config file via http call)
  • But then, in useFactory of APP_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 into main.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) :
fetchConfig().then(config => {
	platformBrowserDynamic([{provide: ConfigData, useValue: config}])
		.bootstrapModule(AppModule)
		.catch(err => console.log(err));
});

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

3reactions
angular-robot[bot]commented, Jun 4, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found