Search code examples
angularposthttp-postangular5angular2-services

How to pass Body to POST method in angular 2


In my scenario,body of the POST method is like-

{ "deleteList" :[ "5ab32csa2" , "5baweq34da" , "5cwqr5wer" ] }

I want to send this data object to the POST method same as above. I tried with many different postings with headers an body and Finally I got the below answer...====>>


Solution

  • And I got the answer====>

     deletemyData(selectedIdList){
      return this.http.post(
          this.deletemyDataUrl,
          JSON.stringify ({ deleteList : selectedIdList }) ,
          { headers: new HttpHeaders().set('Content-Type', 'application/json')}
        ); 
      }