I'm using Angular 16 and I have a specific scenario: My application will run locally in many machines, each one with one different ip, so that means that every server url will be different. Currently, I'm getting this url from the environment.ts, like this:
export const environment = {
apiUrl: 'http://11.22.33.44:5678/',
};
Currently, every time I need to build the application, I change the url manually. I want to do this by a CLI command. i.e ng build --configuration=production --serverUrl=http://55.66.77.88:5678/.
This is my angular.json production section
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.development.ts",
"with": "src/environments/environment.ts"
}
]
}
I have read this question, but it says that I'll need to create one environment for each scenario. It's not fully dynamic.
First, try to set a placeholder value for
apiUrl:Then, when building your project you can use the
--envoption to specify theapiUrlenvironment variable value, like: