Http post ionic4

I am Using Post Data With Http In ionic 4. My Sample Data Is Like this,
“employee”: {
“name”: “abcd”,
“mobile”: “8229678323”
my Code,

import { Http , Headers } from ‘@angular/http’;

var data = JSON.stringify({ employee: { name: “abcd”, mobile: “8229678323”}});

let headers = new Headers();
headers.append(‘Content-Type’, ‘application/json’);
let options = { headers: headers };,data,options).subscribe(data =>{
},error => {
alert("Error "+ error.error);

I Got Error Undefined. Please Help me to Solve this.

Are you using cordova-plugin-advanced-http, I imagine.

You have not to stringify the object, but pass the objects to the plugin.

In the constructor remember to put:

constructor(private http: HTTP)  {

see here


PS: please use the formatter for code, the </> icon.

Thanks And I Will Try.

Before you start worrying about cordova plugins, I would suggest simply trying HttpClient.

1 Like

Thank You pimol it is Working…