hello I have finished learn angular 7 basics now have combined django from the back and angular for the from I am in the start of this project
now I am using rest_framework for django and I want angular to send a GET request to the backend as we know django uses 127.0.0.1:8000 and angular 127.0.0.1:4200 and when I do this function
export class HomeComponent implements OnInit {
users: Object;
recvedData: boolean = false;
hasError: boolean = false;
constructor(private http: HttpClient) { }
ngOnInit() {
this.http.get('/api/qutes').subscribe(data => {
this.users = data;
console.log(data);
}, error => {
this.recvedData = true;
this.hasError = true;
console.log(error);
})
}
}
I am trying to get data from /api/quets from the backend server
but it requesting the data from the frontend server (127.0.0.1:4200/api/quets) and this URL does not exists I know I can add a service with variable domain = "127.0.0.1:8000" and to this.http.get(this.service.domain +"/api/quets")
my question:
there is a better way to do that? so it send all of the request to the
backendserver automatically?
this.http.get("api/quotes")and notthis.http.get("127.0.0.1:8000/api/quotes")apiitself contains127.0.0.1:8000/api/, else , you cannot AFAIN.