1

I'd like to be able to do something like this:

<img src="{{photoUrl.replace('upload/', 'upload/' + environment.someVariable)}}">

I can access my environment variables inside my .TS file like below but it's not recognized in the HTML file.

import { environment } from 'src/environments/environment';


ngOnInit(): void {
  const something = environment.someVariable;
}
2
  • yes just create one property in component then assign the value of your environment environment = environment.someVarible; Commented Sep 13, 2021 at 18:32
  • @Indraraj26, answers go down there. Commented Sep 13, 2021 at 18:32

1 Answer 1

3

yes just create one property in component then assign the value of your environment.

ts:

public environment = environment;

html:

{{environment.someVariable}}
Sign up to request clarification or add additional context in comments.

6 Comments

I know that's the easy way, just seeing if there is a way to access the environment variables without creating a new variable inside the .ts file. It seems like there should be a way!? FYI - I have lots of these variables, not just 1 and it would be on multiple pages. So i would be doing lots of variable creation in each .ts file, which is what I'd like to eliminate.
Short Answer:NO, You can create directive or Pipe, Basically use pipe to alter it i would say according to environment.
You pass an value it will concat with environment.someVariable return modifiedValue
That seems like a lot more work as I would have to create a custom pipe. And the environment variables would still have to be read in the custom pipe file, right?
Yes but with that you will not have to import environment anywhere and create tons of variable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.