UNPKG

ng-metamagic-extensions

Version:

[![npm version](https://badge.fury.io/js/ng-metamagic-extensions.svg)](https://badge.fury.io/js/ng-metamagic-extensions) [![TeamCity CodeBetter](https://img.shields.io/teamcity/codebetter/bt428.svg)]() [![NPM](https://nodei.co/npm/ng-metamagic-extension

87 lines (76 loc) 2.07 kB
/** * Created by dattaram on 30/5/17. */ import {Injectable} from "@angular/core"; import {Http, Headers, RequestOptions} from "@angular/http"; @Injectable() 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); } }