Wednesday 28 March 2018

NG5-PostApplicaotinJSONToformData

NG5-PostApplicaotinJSONToformData
----------------------------------------------

Send the post data as Form data based
i.e => key1=val1&key2=val2..... from Object(json type)
Application type to form data type


component.ts
--------------
let data = {
    "key1":"val1",
    "key2":val2",
    "key3":"val3"
}
let PostObj = this.toParams(data)
  this._MyService.CreatePost(PostObj).subscribe( (data:any) => {
    try{
    }
    catch(e){
    }
});
           
 toParams(evtObj) {
    var p = [];
    for (var key in evtObj) {
        p.push(key + '=' + encodeURIComponent(evtObj[key]));
    }
    return p.join('&');
}



No comments:

Post a Comment