Created
April 20, 2021 03:41
-
-
Save ScriptBytes/485a9d509b0f8bf1b772931da48b1b38 to your computer and use it in GitHub Desktop.
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
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