Multiple Objects into HttpParams

后端 未结 3 1782
孤街浪徒
孤街浪徒 2021-02-08 07:00

I have some categories in a formcontrol, I send them in an array of string like this:

[1,4,6]

And that is my actual code:



        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 07:35

    May be this is what you are looking for

    component file:

    import { Component } from '@angular/core';
    import { HttpParams } from '@angular/common/http';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    
    export class AppComponent {
    
    data = [
           {id:'_', title:'_', content:'_'},
           ....,
           ....
           ];
    
    mainArr:any = [];
    
    constructor(){}
    
    getCategory(item){
        this.mainArr.push({title:item.title,content:item.content,categoryId:item.id});
    
       console.log('mainArr',this.mainArr);
    
       let requestOptions = {
            params: new HttpParams()
            .append('data', this.mainArr),
            withCredentials: true
        }
    
       console.log('requestOptions',requestOptions);
      }
    }
    

提交回复
热议问题