Send JSON in Http Get request with Angular.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Http, Headers, RequestOptions, Response, ResponseContentType, URLSearchParams} from "@angular/http"; | |
@Injectable() | |
export class DocumentService | |
{ | |
constructor(private http: Http) | |
{ | |
} | |
loadDocuments(folderId: number, currentPage: number) : Observable<Response> | |
{ | |
let headers = new Headers({ | |
'Content-Type' : 'application/json', | |
'Accept': 'application/json' | |
}); | |
let requestOptions = new RequestOptions({headers}); | |
requestOptions.params = this.getFilterData(currentPage); | |
let path = "folders/"+folderId+"/documents"; | |
return this.http.get(appConstants.apiUrl+ path, requestOptions ); | |
} | |
private getFilterData(currentPage: number) : any | |
{ | |
let params: URLSearchParams = new URLSearchParams(); | |
let filterValue = JSON.stringify( {currentPage: currentPage, pageLimit: 50 }); | |
params.set('filter', filterValue); | |
return params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment