I’m having trouble with GET requests in my Angular2 app after switching from a forked starter project to a new one created with Angular CLI. The Express backend seems fine, but the requests aren’t working anymore.
Can someone help me figure out why the GET requests aren’t working in the new setup? I’m not sure if it’s a problem with my logic or how I’m connecting Express to Angular. Any advice would be great!
I encountered a similar issue when transitioning to Angular CLI. One crucial step often overlooked is configuring CORS on your Express backend. Ensure you’ve installed the ‘cors’ package and implemented it in your server.js or app.js file:
const cors = require('cors');
app.use(cors());
Additionally, verify that your Angular service is using the correct URL for API calls. If your backend is running on a different port, you’ll need to specify the full URL:
Lastly, double-check that your HttpClientModule is properly imported in your app.module.ts. These steps should resolve most common GET request issues in Angular CLI projects.
hey ryan, had similar issues after switching to angular cli. make sure ur proxy config is set up right in angular.json. also check if the base url for api requests is correct in ur environment files. sometimes its the little things that trip us up!
hmmm, interesting problem! have u tried using the httpClient instead of http? it’s the newer way in angular. also, double-check ur imports - sometimes they get messed up when switching projects. oh, and make sure ur backend is actually running when u test. lemme know if any of that helps!