1

I have an API project and an Angular Project under the same solution in .NetCore. My angular project is calling the APIs from the API project. In order to access the APIs,i have put the baseurl of the API in the Environment.ts and Environment.prod.ts file. But after publishing the project i realized the Environment files are not created. Now for some reason the baseurl of the API got changed. How do i replace the new API url without publishing the Angular Project all over again.

1
  • Any update on this ? Did my answer solve your problem ? Commented Aug 30, 2019 at 4:44

2 Answers 2

1

But after publishing the project i realized the Environment files are not created.

You wont see the env file because it's already bundle every everything into js file

There is not other way to do that without publishing your solution again.

You have to build everything again and again to update your code change there is no way way around.

Update: To import json into your angular app simply use require like this

const jsonData = require('/assets/appsetting.json');

You can view another answer here I wont go through it again because there are already an answer

Sign up to request clarification or add additional context in comments.

5 Comments

is there a way i can put it in appsetting.json and access it from there
You mean you want to acccess appsetting.json from angular or .net core ?
i can see an appsetting.json file in the angular project.So can i put the url there and access it from any ts file
you can but you need to put the appsetting. json inside asset folder then import into ts file
can you please give me an example
0

Indeed, as you've noticed, the environments files are not available because they have been integrated into the built artifact. If you want to dynamically change the environments URL, you will have to code the logic: a service that fetch the API urls on some kind of server.

Usually, if it's just an environment URL to change, I find it is enough to just rebuild the site, as the rebuild is fairly quick.

Comments

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.