I am currently diving into the world of Angular at my workplace, even though I do not have a background in web development.
One challenge I am facing is how to encapsulate API calls within one of my components without knowing where to begin.
The component in question is a datagrid (based on mat-table) that offers features like pagination, sorting, and navigation between pages.
As it stands, whenever I use this component in a project, I find myself creating a separate service for calling the API and handling tasks such as pagination, sorting, and moving between pages outside of the component itself.
My goal is to streamline these API actions within the datagrid so that if another project decides to utilize my component library, all necessary functionality is already integrated.
While I am currently studying the Services tutorial on angular.io, it does not address this specific issue.
So far, I have developed a BaseAPIService
from which services classes interfacing with APIs will inherit.
export declare class BaseAPIService {
private httpClient;
constructor(httpClient: HttpClient);
protected request<T>(method: string, url: string, options?: any): Subject<T>;
protected get<T>(url: string, options?: any): Subject<T>;
protected head<T>(url: string, options?: any): Subject<T>;
...
}
In a project using my datagrid, we might have a customers.service
extending the BaseApiService
. However, I struggle with passing the URL and configuration from the customer.service
to the component.
Is this scenario feasible?