ng-metamagic-extensions
Version:
[](https://badge.fury.io/js/ng-metamagic-extensions) []() [ • 1.37 kB
text/typescript
import {Injectable} from "@angular/core";
import {Http, Headers, RequestOptions} from "@angular/http";
/**
* Created by ketan on 15/11/16.
*/
()
export class CheckBoxGroupService {
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);
}
}