确保在根目录下有一个proxy.config.json文件
确保proxy.config.json中的代理路径和目标路径正确配置
例如,如果您的Angular应用程序位于http://localhost:4200并且您的API服务于http://localhost:3000,则可以将proxy.config.json配置为:
{ "/api/*": { "target": "http://localhost:3000", "secure": false, "logLevel": "debug" } }
"start": "ng serve --proxy-config proxy.config.json"
在终端中运行npm start以启动应用程序,并确保没有任何错误消息出现
使用代理路径访问API,如:
this.http.get('/api/endpoint').subscribe(response => { console.log(response); });