首页 > 解决方案 > 如何在 Angular 6 api 调用中将数组对象作为参数传递

问题描述

在下面的代码中,companyId是一个对象数组,我想将其作为 API 调用的参数传递,我该怎么做?

getItems(): void {
    this.urlcall()
        .subscribe(
        restItems => {
            this.vehicle = restItems;
            console.log('Vehicle Data=',this.vehicle);
        });
}

urlcall() {
    return this.http.get<any[]>(this.Url, { responseType : 'json',params : this.params ,headers : this.httpHeaders } )
       .pipe(map(data => data));
}

public params = new HttpParams()
    .set('CompanyID',  this.companyID )
    .set('vehicleId', '23')
    .set('currentOdometer', this.cOdometer);

public httpHeaders = new HttpHeaders() 
    .set('Accept','application/x-www-form-urlencoded');

标签: angulartypescript

解决方案


推荐阅读