无法通过将电子邮件作为角度参数传递来获得API响应

问题描述 投票:0回答:1

我无法通过调用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使其为空

angular api http post service
1个回答
0
投票

尝试以下代码通过将电子邮件作为参数来获得响应

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)
      }
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.