Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Injecting a constant into another gets undefined #14168

Closed
kikar opened this issue Mar 3, 2016 · 4 comments
Closed

Injecting a constant into another gets undefined #14168

kikar opened this issue Mar 3, 2016 · 4 comments

Comments

@kikar
Copy link

kikar commented Mar 3, 2016

I'm reporting a bug.
When trying to inject a constant into another constant function, it just gets undefined. It should instead inject the other constant

Here is the fiddle demo of the issue. https://jsfiddle.net/kikar/fy39qq1m/

The reason for this behavior is to be able to define a constant based on the value of another one, like API base url, based on type of enviroment.

Not working in angular 1.5.0 and 1.4.8

@Narretz
Copy link
Contributor

Narretz commented Mar 3, 2016

This looks like it works as expected. A constant is basically a special version of a value - they have in common that both are not injectable, they are really just used for the simplest of use cases. I guess the docs should make that clearer.

@Narretz Narretz added this to the Backlog milestone Mar 3, 2016
@Narretz
Copy link
Contributor

Narretz commented Mar 3, 2016

You should simply use a factory: .factory('SECOND', secondConst)

@kikar
Copy link
Author

kikar commented Mar 3, 2016

Thanks for the reply. But why can I inject them into a controller if they're not injectable?

@Narretz
Copy link
Contributor

Narretz commented Mar 3, 2016

I meant you can't inject into them, but you can inject them into other
things. So your example doesn't work because Second can't be injected with
First.
Am 03.03.2016 16:30 schrieb "Gady" [email protected]:

Thanks for the reply. But why can I inject them into a controller if
they're not injectable?


Reply to this email directly or view it on GitHub
#14168 (comment)
.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants