ng-metamagic-extensions
Version:
[](https://badge.fury.io/js/ng-metamagic-extensions) []() [ • 2.07 kB
text/typescript
/**
* Created by dattaram on 30/5/17.
*/
import {Injectable} from "@angular/core";
import {Http, Headers, RequestOptions} from "@angular/http";
()
export class ScrollViewService {
parentRef : any;
responseData : 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);
}
fetchLazyData(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.setLazyData();
}
);
}else if(methodType == "get"){
this._http.get(serviceUrl,options).subscribe(
response=>{
this.responseData = response.json();
},
error=>{
},
()=>{
this.setLazyData();
}
);
}
}
setLazyData (){
this.parentRef.setLazyData(this.responseData);
}
}