-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Default Query String Params #938
Comments
I was trying to do the same thing but in the end I made sure the server response with list data has all the information. Server side has to have defaults anyway, so my pagination code uses the numbers from server response instead of the state values. The state does have the same URL arguments you have, but they only become explicit when user goes to another page or changes the order. Still, it would be nice to be able to specify the default values, but they would be default state values, not default query values, I guess. |
I think you are right in that it should be separate from the URL in that it should just be default $stateProvider.state('products', {
url: '/products/:category?page&limit&orderBy&direction',
controller: 'ProductsCtrl as ProductsCtrl',
templateUrl: 'app/products/template.tpl.html',
defaultStateParams: {
category: 'featured',
page: 1,
limit: 25,
orderBy: 'popular'
}
}); So the url {
category: 'featured',
page: 1,
limit: 25,
orderBy: 'popular'
} And the url {
category: 'new',
page: 2,
limit: 100,
orderBy: 'popular'
} |
Fixed in a472b30. Will be merged to master shortly. |
please help me how to set static value in query string this is my code
|
This is something that has plagued me for the last couple of months. When doing things like pagination, I like to use query strings. It doesn't matter what order they are in, they are optional, and it's industry standard. What I don't like is that I can't set a default value for each of the query strings that I register with my state. So in my
resolve
I have to check if something likepage
is empty, if it is, set it to 1. Or iflimit
is empty, set it to 25. If I could just pass the current$stateParams
straight to my XHR call without having extraneous code checking for defaults that would be fantastic.So have something like this:
Then if someone landed on
/products
, the$stateParams
would be:If the url was
/products?orderBy=price&direction=desc
, the$stateParams
would be:I am willing to put in the work to get this done. I just want to make sure it's something that is needed and will get merged in :).
The text was updated successfully, but these errors were encountered: