Using Default Parameters in the ngrx getWithQuery() Function

Curiosity strikes me on how to send the default data already present in getWithQuery(), just like this:

@Injectable({providedIn: 'root'})
export class CompaniesDataService extends DefaultDataService<Company> {
    private readonly _URL: string = '/api/companies';
    private readonly _DEFAULT_QUERIES: QueryParams = {top: '0', limit: '10', order: "name"};

    constructor(http: HttpClient, httpUrlGenerator: HttpUrlGenerator) {
        super('Company', http, httpUrlGenerator);
    }

    getWithQuery(queryParams: QueryParams | string = this._DEFAULT_QUERIES): Observable<Company[]> {
        return this.http
            .post<FmsHttpResponse<Company>>(`${this._URL}/search`, queryParams)
            .pipe(map(response => response.content));
    }
}

What I mean is to have this._DEFAULT_QUERIES as the default parameter for queryParams in getWithQuery().

However, upon adding a resolver function like this:

return this.companyEntityService.getWithQuery()
  .pipe(tap(() => this.companyEntityService.setLoaded(true)));

An error occurs:

Expected 1-2 arguments, but got 0.
.

Any insights? Just to mention, I am relatively new to ngrx programming and it's possible that the solution is simpler than I realize.

Answer №1

Is it necessary to pass something that already exists in the class as a parameter? What if we try a different approach like this:

 fetchData(queryOptions: QueryOptions | undefined): Observable<Item[]> {
       if(queryOptions === undefined){
           queryOptions = this._DEFAULT_OPTIONS;
       }
        return this.http
            .post<ApiResponse<Item>>(`${this._URL}/fetch`, queryOptions)
            .pipe(map(res => res.data));
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring the completion of all validations in Angular 4

Currently, I'm working on a project that involves 3 FormControls. I am in need of a validation process that ensures either all three have values selected or none at all. Is there a method to achieve this type of validation? ...

The child module invokes a function within the parent module and retrieves a result

Guardian XML <tr [onSumWeights]="sumWeights" > Algorithm sumWeights(): number { return // Calculate total value of all weights } Offspring @Input() onTotalWeights: () => number; canMakeChanges() { return this.onTota ...

Angular 5 error handler does not support service calls

My HTTP calls are placed inside a service, as they should be. Within that service, I inject another service for handling error notifications. In an interesting turn of events, I noticed that when I place the notification call inside the catchError pipe, e ...

Exploring Attack on Titan alongside the concept of dynamic route templates in coding

I am currently working on creating a factory for an UrlMatcher. export const dummyMatcher: UrlMatcher = matchUrlFn(sitemap as any, 'dummy'); export const routes: Routes = [ { matcher: dummyMatcher, component: DummyComponent }, { path: &apos ...

Difficulty reloading after updating input using AngularJS ngTable

I'm encountering an issue where I need to utilize ngTable with TableParams to load and modify a table. For instance, when the page initializes, entering a number in the textbox for the first time displays the appropriate number of rows in the table. ...

Angular's array filter functionality allows you to narrow down an

I am working with an Array and aiming to filter it based on multiple criteria: primasSalud = [ { nombre: 'one', internacional: true, nacional: false, nacionalSinReembolso: false, nacionalClinicasAcotadas: false ...

Here is an example showcasing how to use Angular 2 to make an

How can I correctly retrieve json data from an http get request in Angular 2? Currently, I am working on testing some local data with a mocked endpoint. Although I am able to see the result in the http.get() method, I am facing issues when trying to assign ...

Using MatTableDataSource in a different Angular component

I am working with two components, namely Order and OrderDetail. Within the Order component, I have a MatTableDataSource that gets populated from a service. OrderComponent Prior to the constructor listData: MatTableDataSource<DocumentDetailModel>; ...

Bring in services from a neighboring module within Angular 2

In my Angular 2 project, the module structure is as follows: app |-module1 |-module2 |-component2-1 |-component2-2 |-factories The factories module contains various providers defined in this manner: @NgModule({ provi ...

Angular: Streamlining the Constructor Function for Efficiency

Consider the scenario where we have these two components: export class HeroComponent { constructor( public service1: Service1, public service2: Service2, ) { // perform some action } } export class AdvancedHeroComponent extends HeroCompone ...

What is preventing the mat-slide-toggle from being moved inside the form tags?

I've got a functioning slide toggle that works perfectly, except when I try to move it next to the form, it stops working. When placed within the form tag, the toggle fails to change on click and remains in a false state. I've checked out other ...

The patchState function is iterated within the NGRX component-store effect

My program is stuck in an infinite loop and I can't figure out why. interface LatestAppointmentsWidgetState { loading: boolean; page: number; pagedData: Paged<Appointment>; } @Injectable() export class LatestAppointmentsWidg ...

What is the best way to display information pulled from an API in Angular using ng2 charts?

Hello, can you lend me a hand? I'm currently facing an issue while attempting to display data using ng2 charts in my Angular application. The data is being fetched from a Firebase API, but unfortunately, it's not rendering properly and I can&apos ...

Dynamically populate dropdown menu with values extracted from dataset

I'm currently working on a dropdown menu that needs to be updated dynamically using the data set below: this.additionalPercentages = this.offer.offerData.wellbeing.retirementPackages[0].additionalVoluntaryContributionPercentages; When I console this ...

The Replay Subject will not activate the async pipe when utilizing the subscribe shorthand during initialization

I'm curious about the behavior of a replay subject created using the subscribe shorthand method, specifically why it does not trigger the async pipeline when the next method is called. When I follow this approach, everything functions as expected: ex ...

I am a beginner in the world of Typescript/Angular, and I have encountered a compiling error TS2339. It seems that even when the condition *ngIf="x.length > 0;" should be false, the

I'm currently enrolled in a Typescript/Angular course where I am learning about the implementation of "*ngIf". During one of the lessons, the instructor provided an example using an empty array to demonstrate how it fails the condition and results in ...

Unlock the Potential: Empowering Users with Nativescript Firebase Sign

Recently, I embarked on the journey of developing apps using NativeScript and Angular. Looking for a reliable database source, I decided to go with Google Firebase. Successfully migrating my SQL data to the Firebase real-time database, I am now able to s ...

Angular is programmed to actively monitor the status of elements for enabling or

Seeking a solution to determine if an element is disabled in an Angular directive. Have attempted with host listeners, but no success yet. Directive: @HostBinding('attr.disabled') isDisabled : boolean; @HostListener("disabled") disabled() { ...

Switching a div class in Angular 6 with a button click: A step-by-step guide

In this scenario, I have a div with the class name old. There is also a button that, when clicked, should toggle the div's class name between old and new. I am looking for a solution using Angular 6. Below is the code snippet: I am relatively new to ...

Compiler is unable to comprehend the conditional return type

I've done some searching, but unfortunately haven't been able to find a definitive solution to my issue. Apologies if this has already been asked before, I would appreciate any guidance you can offer. The problem I'm facing involves a store ...