To avoid CORS errors, you should proxy the calls so that the application always calls itself, then the proxy takes care of redirecting the calls.
So, first we create the proxy.conf.json
.
touch proxy.conf.json`
Inside it we put an initial configuration, e.g:
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
In the package.json
we modify the start command:
"start": "ng serve --proxy-config proxy.conf.json"
Restart the application and we're there!
here you can read about the proxy.
Enjoy!