chuckd
chuckd

Reputation: 14520

Can I access my environment variables inside a HTML file in Angular

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;
}

Upvotes: 1

Views: 4331

Answers (1)

Indraraj26
Indraraj26

Reputation: 1966

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

ts:

public environment = environment;

html:

{{environment.someVariable}}

Upvotes: 3

Related Questions