Giter VIP home page Giter VIP logo

Comments (9)

NetanelBasal avatar NetanelBasal commented on July 20, 2024 1

I don't mind getting a PR that adds built-in support for it. If you can't, in the meantime, you can use a function to convert it.

from cashew.

NetanelBasal avatar NetanelBasal commented on July 20, 2024

Can you please reproduce it on stackblitz?

from cashew.

chris480 avatar chris480 commented on July 20, 2024

Replicated on SB: https://stackblitz.com/edit/angular-ivy-n6csyb?file=src%2Fapp%2Fhello.component.ts
Also occuring on A11

Using jsonplaceholder as a fake api service

from cashew.

NetanelBasal avatar NetanelBasal commented on July 20, 2024

Why you're not using a pojo?

    const params = {
      api_key: "1234",
      url: "https://google.com/"
    };

    this.http
      .get(
        "https://jsonplaceholder.typicode.com/todos/",
        withCache({ ...params })
      )

from cashew.

chris480 avatar chris480 commented on July 20, 2024

The HttpParam object is an output from another component. All the services were given HttpParams by default. If cashew doesn't have a native way to convert them, I can just create a function to change httpparam to an object.

Just wanted to check if I was missing something in cashew. If not, it's all good and we can close this out.

from cashew.

kauppfbi avatar kauppfbi commented on July 20, 2024

I also had some issues today when I used the library the first time.
I wanted to create a PR, but when I further investigated the issue, I found the solution to this problem (which is inside the application code) :

const  params = new HttpParams();
params = params.append('context', context)

// w/o cashew
// const options = {params};

// example above ("wrong approach"):
// const options = withCache({...params});

// with cashew ("right approach"):
const options = withCache({params});

this.http.get(url, options).subscribe();

I also adjusted the Stackblitz example, which is now working as expected: https://stackblitz.com/edit/angular-ivy-erpgym?devtoolsheight=33&file=src/app/hello.component.ts

from cashew.

kauppfbi avatar kauppfbi commented on July 20, 2024

Okay, nevermind my comment before.
Coming back to work topics, I need to see, that it is still not working correctly.

I recognized, that the request url to the api is not built correctly. This is what happens:
It builds a url in the format like this: <baseUrl>/api/v1/items?params=foo=bar&bar=foo

I don't know why, but it appends an additional params=. Without, everything would work fine

from cashew.

sysmat avatar sysmat commented on July 20, 2024
  • wrong types in
export declare function withCache(params?: Params): {
    params: Params;
};
  • in http.d.ts
get<T>(url: string, options?: {
        headers?: HttpHeaders | {
            [header: string]: string | string[];
        };
        observe?: 'body';
        params?: HttpParams | {
            [param: string]: string | string[];
        };
        reportProgress?: boolean;
        responseType?: 'json';
        withCredentials?: boolean;
    }): Observable<T>;
  • So withCache should return type as http.d.ts, so If I can't add auth headers is not useful
  • I think withCache should return HttpParams
  • using angular 11

from cashew.

NetanelBasal avatar NetanelBasal commented on July 20, 2024

The library now uses context.

from cashew.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.