我不熟悉Angle 6,并尝试通过以下链接的代理进行API调用。
angular 6 proxy configuration for api call
但是我无法从服务器获得响应,并且终端显示以下错误
[HPM] Error occurred while trying to proxy request /api/file2.php from localhost:4200 to http://localhost:1234 (ECONNREFUSED (https://nodejs.org/api/errors.html#errors_common_system_errors)
service.ts
import { Injectable } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
interface myData{
obj:Object;
}
@Injectable({
providedIn: 'root'
})
export class RecordsService {
constructor(private http:HttpClient) {
this.recordFunc();
}
recordFunc() {
let headers=new HttpHeaders();
return this.http.get<myData>('/api/file2.php');
}
}
proxyconfig.json
{
"/api":{
"target":"http://localhost:1234",
"secure":false,
"changeOrigin":true
}
}
我不明白这里是什么问题。我按照视频中的说明进行操作。