ng-metamagic-extensions
Version:
[](https://badge.fury.io/js/ng-metamagic-extensions) []() [ • 1.37 kB
text/typescript
/**
* Created by ketan on 4/11/16.
*/
import{Injectable} from '@angular/core';
import {Http, RequestOptions, Headers} from '@angular/http';
()
export class DataTableService {
responseData : any;
parentRef : any;
constructor(private _http : Http){
}
fetchData(parentRef : any, serviceUrl : string, methodType: string){
this.parentRef = parentRef;
let requestJson = {};
let headers = new Headers({ 'Content-Type': 'application/json;charset=UTF-8' });
let options = new RequestOptions({headers : headers,method : methodType});
if(methodType == "post"){
this._http.post(serviceUrl,requestJson,options).subscribe(
response=>{
this.responseData = response.json();
},
error=>{
},
()=>{
this.setData();
}
);
}else if(methodType == "get"){
this._http.get(serviceUrl,options).subscribe(
response=>{
this.responseData = response.json();
},
error=>{
},
()=>{
this.setData();
}
);
}
}
setData (){
this.parentRef.setData(this.responseData);
}
}