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.
-
Any update on this ? Did my answer solve your problem ? – Tony Ngo Aug 30 '19 at 04:44
2 Answers
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

- 19,166
- 4
- 38
- 60
-
is there a way i can put it in appsetting.json and access it from there – Punam Goswami Aug 29 '19 at 06:14
-
You mean you want to acccess appsetting.json from angular or .net core ? – Tony Ngo Aug 29 '19 at 06:14
-
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 – Punam Goswami Aug 29 '19 at 07:35
-
you can but you need to put the appsetting. json inside asset folder then import into ts file – Tony Ngo Aug 29 '19 at 07:54
-
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.

- 840
- 2
- 7
- 18