Skip to content

Instantly share code, notes, and snippets.

@ScriptBytes
Created April 20, 2021 03:41
Show Gist options
  • Save ScriptBytes/485a9d509b0f8bf1b772931da48b1b38 to your computer and use it in GitHub Desktop.
Save ScriptBytes/485a9d509b0f8bf1b772931da48b1b38 to your computer and use it in GitHub Desktop.
load(filter = '', order = '', page = 0, pageSize = 0, useCache = false, append = false) {
if (useCache && this.items?.length > 0) {
return;
}
this.loading = true;
const url = this.settings.url + `?filter=${filter}&order=${order}&page=${page}&pageSize=${pageSize}`;
this.http
.get<T[]>(url)
.pipe(
catchError((e) => {
this.loadError = e;
return throwError(`Error loading ${this.settings.itemName}s`);
}),
finalize(() => (this.loading = false))
)
.subscribe((res) => {
if (append) {
this.items = this.items.concat(res);
} else {
this.items = res;
}
if (res.length === 0) {
this.noLoadResultsSubject.next();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment