0
votes

In my Ember application I use query params to refresh model data and present new information. I have a use case that requires the ability to clear all the data and start with 'fresh' filters.

I'm attempting to create a 'reset' button in my ember application. This button should revert the existing query parameters in the URL to null.

The query parameters are configured on the route as follows:

export default Route.extend({
  queryParams: {
    dateFrom: {refreshModel:true},
    dateTo: {refreshModel:true},
    hours: {refreshModel:true}
  }
}),

I tried the following action on the route and controller seperately:

resetParams() {
      this.set('queryParams.hours', null)
    }

I have also tried simply this.set('hours', null) but it doesn't make a difference. The Ember documentation doesn't discuss clearing the params, just stopping them from being sticky.

1

1 Answers

1
votes

the queryParams are always present on the controller. So on the controller you have something like queryParams: ['dateFrom', 'dateTo', 'hours']. Then you can directly docontroller.set('dateFrom', null)to set thequeryParam`.

So on the route you can do this.controller.set('dateFrom', null), and on the controller this.set('dateFrom', null).

Its a bit confusing because the configuration for the queryParams is scattered over routes and controllers. However the values for the queryParams are always direct route properties. And not nester under a queryParams object. That is only the configuration.