Skip to content

Instantly share code, notes, and snippets.

@NazemMahmud
Last active December 18, 2021 11:14
Show Gist options
  • Save NazemMahmud/fbdda84ee4087b4102066ff3bad8bf46 to your computer and use it in GitHub Desktop.
Save NazemMahmud/fbdda84ee4087b4102066ff3bad8bf46 to your computer and use it in GitHub Desktop.
Angular Material: main service ts file for pagination sample
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http';
@Injectable()
export class MainService {
constructor(protected http: HttpClient) {}
private readonly baseUrl = "127.0.0.1:8000/api"; // here use your project's base url
private additionalUrl = "/employees"; // here use your remaining route url
protected _url = `${this.baseUrl}${this.additionalUrl}`;
getAll(pageOffset: any, page, orderBy?): Observable<any> {
const params = new HttpParams({
fromObject: {pageOffset, page, orderBy}
});
return this.http.get(`${this._url}`, {params: params ? params : null});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment