troyanskiy/ngx-resource

After upgrading to ngx-resource 3.0.0 query params are not added to url

desfero opened this issue · 17 comments

as in title. Query params are not added to url.

Maybe somethinng wrong happen here:

Resource.prototype.$_resolveMainOptions = function (shell) {
        // shell.data contains passed object to resource action (customersResource.query({ ... })
        return Promise
            .all([
            Promise.resolve(shell.options.url || this.$getUrl(shell.options)),
            Promise.resolve(shell.options.path || this.$getPath(shell.options)),
            Promise.resolve(shell.options.headers || this.$getHeaders(shell.options)),
            Promise.resolve(shell.options.params || this.$getParams(shell.options)),
            Promise.resolve(shell.options.data || this.$getData(shell.options))
        ])
            .then(function (data) {
            return {
                url: data[0],
                path: data[1],
                headers: new Headers(data[2] ? Object.assign({}, data[2]) : data[2]),
                params: data[3] ? Object.assign({}, data[3]) : data[3],
                data: data[4] ? Object.assign({}, data[4]) : data[4]
            };
        });
    };

+1 +1

niuba commented

+1+1

@troyanskiy is there any updates about this bug?

Hello. Do you have any details?
I can't reproduce that on my project.

Could you please provide some code example of resource and how you call it?

Thank you.

@troyanskiy currently i'm out of my computer, but you can look at #118

Hello again to all.
Could you please tell me your angular version?
I think it's related to angular 2 only, since they (angular developers) deprecates search param on request options I switched to params param.

File: https://github.com/angular/angular/blob/master/packages/http/src/interfaces.ts#L48-L58

export interface RequestOptionsArgs {
    url?: string;
    method?: string | RequestMethod;
    /** @deprecated from 4.0.0. Use params instead. */
    search?: string | URLSearchParams | {
        [key: string]: any | any[];
    };
    params?: string | URLSearchParams | {
        [key: string]: any | any[];
    };
    headers?: Headers;
    body?: any;
    withCredentials?: boolean;
    responseType?: ResponseContentType;
}

Thank you.

So please test updated version v3.0.2.
Also please reply here what version of angular do you have with the bug.
If you have angular 2, please test it with parameter angularV2: true on ResourceParams

Ex:

@Injectable()
@ResourceParams({
  url: 'https://api.github.com/user',
  angularV2: true
})
export class GitHubUserService extends Resource {
  @ResourceAction({
    isArray: true,
    path: '/repos'
  })
  getRepos: ResourceMethod<IQueryInput, any[]>;
}

@troyanskiy i have this bug on latest angular (from 4 line). Let me check tommorrow if it is working

So that is strange. I can't reproduce it.
Will be nice to have some project what I can easy npm i and start to test the issue.

niuba commented

@troyanskiy i have this bug on angular4.0.0,the shell.options.data || this.$getData(shell.options)` always be ""

3.0.2 doesn't fix it for me. I run angular 4.1.3.

Thank you for the replies.
As I said above I can't reproduce that on my projects, so I will be nice to have some small project which I can easily start to debug.
Thank you.

see plunker

should be request url '/user?ps=10', but only '/user'.

@cipchk Thank you. I will check it today.

Voilà! It's fixed!

Works, thanks a lot