fullstackproltd / AspNetCoreSpa

Asp.Net 7.0 & Angular 15 SPA Fullstack application with plenty of examples. Live demo:
https://aspnetcorespa.fullstackpro.co.uk
MIT License
1.47k stars 464 forks source link

DataService.Get() HttpParams always empty #205

Closed lukasvencalek closed 6 years ago

lukasvencalek commented 6 years ago

In DataService, get method calls buildUrlSearchParams where the httpParams object is set. However, httpParams object is immutable (https://github.com/angular/angular/issues/19044) so after calling of append, it is required to set the object back into the variable, otherwise it is always empty.

To fix the issue, the method should look like this:

private buildUrlSearchParams(params: any): HttpParams {
        let searchParams = new HttpParams();
        for (const key in params) {
            if (params.hasOwnProperty(key)) {
                searchParams = searchParams.append(key, params[key]);
            }
        }
        return searchParams;
    }
asadsahi commented 6 years ago

@Vencalekl thanks for pointing it out. I am guessing changing const to let will do the same trick. Amended it in https://github.com/asadsahi/AspNetCoreSpa/commit/9f0d40df12efd0eca82dee89ae36152417b9fefd. Let me know if it doesn't fix for you.

lukasvencalek commented 6 years ago

@asadsahi, I just tried it without success. It is still required to re-set the variable. Once the HttpParams is immutable, I guess there is no other way of doing that.