Send JSON in Http Get request with Angular.
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