Navjot Angra

Navjot Angra

  • NA
  • 489
  • 249.6k

How Can I post Data(Json object) from Angular 2 to Web api?

Jul 13 2018 1:05 AM
app.component.ts 
 
Step 1: Json Data 
 
this.objsearch=[
                           { "Key": "FirstName", "value": this.firstName },
                           {  "Key": "MiddleName", "value": this.middleName },
                           { "Key": "fatherName ", "value": this.fatherName },
                        ]
 
Method To call service Serice class:
 
this.ServiceObject.saveData(JSON.stringify(this.objsearch))
.subscribe(response => (this._param) = response);
}
 
Service.ts class
 
public _saveDataURL= 'http://localhost:53915/api/ComapnyAndProduct/DeleteItem'; 
          saveData(objSearch: any)
              {
                   return this._http.post(this._saveDataURL,objSearch)
                  .map((response: Response) => response.json());
}
 
Web api
 
    [HttpPost]
     public IHttpActionResult DeleteItem([FromUri]Mregistration objSearch)
    {
   return ok(); 
   }

Answers (2)