greenymaster69
greenymaster69

Reputation: 1516

Ember-data resets queryParam to default value

In my model, I have a queryParam status which is set to refreshModel true in my route.

queryParams: {
    status: {
        refreshModel: true
    }
}

In my controller, this param is set to 'opened' by default :

App.ConversationsController = Ember.ArrayController.extend({
    queryParams: ['status']
    status: 'opened'
});

Everytime I set this param to something else, for example 'all', Ember-data resets it to 'opened' and makes two calls instead of one to my model hook, and this behavior has been observed with breakpoints on my model hook (I don't know where it resets), one with param:opened and one with param:all. I even put an observer on it and it effectively does that.

Note that I already searched my code and there is litteraly nowhere where I set this param back to original value.

Any hints?

Upvotes: 1

Views: 357

Answers (1)

abFx
abFx

Reputation: 313

You have to declare them also in your controller to be an expected param in your route

App.ConversationsController = Ember.ArrayController.extend({
    queryParams: ['status'],
    status: 'opened'
});

Ember has sticky params, as in the docs said.

By default, query param values in Ember are "sticky", in that if you make changes to a query param and then leave and re-enter the route, the new value of that query param will be preserved (rather than reset to its default). This is a particularly handy default for preserving sort/filter parameters as you navigate back and forth between routes

You can check out more here ... ember query params

You can try to reset them in your route

resetController: function (controller, isExiting, transition) {
        if (isExiting) {
          //reset controller to avoid sticky params
          controller.set('status', DEFAULT_VALUE);
        }
    },

Upvotes: 1

Related Questions