我无法通过调用Rest API post方法获得响应,我也尝试过邮递员来获得响应。
我已经尝试了以下代码:data.service.ts
getcategories(){
let headers = new HttpHeaders({'Content-Type': 'application/json'});
let params1 = new HttpParams().set('email',"[email protected]");
let options = {
headers: headers
}
return this.http.post(this.baseUrl+'/courses/get_all_courses/', {params:params1},options);
}
home.componenet.ts;
categories:any;
ngOnInit() {
console.log(this.data.getcategories());
this.data.getcategories().subscribe(
(data)=>{
this.categories=data;
console.log(data);
},
(err : HttpErrorResponse)=>{
console.log("Error in API");
}
);}
通过调用api使其为空
尝试以下代码通过将电子邮件作为参数来获得响应
ngOnInit() {
const params = {
email: "[email protected]"
}
this.data.getcategories(params).subscribe(
(res: any) => {
if (!res) return;
console.log("all data test", res)
this.data = res
},
error => {
console.log("Error in API", error)
}
)
}