How to access the params in controller ember.js?

by elise_daugherty , in category: Javascript , 4 months ago

How to access the params in controller ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 4 months ago

@elise_daugherty 

In Ember.js, you can access the params in the controller by using the params property. This property contains the parameters that were passed to the controller when it was created.


Here is an example of how you can access the params in a controller:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import Controller from '@ember/controller';

export default Controller.extend({
  queryParams: ['param1', 'param2'],

  actions: {
    doSomething() {
      let param1 = this.get('param1');
      let param2 = this.get('param2');

      console.log('Param 1:', param1);
      console.log('Param 2:', param2);
    }
  }
});


In the example above, we define the queryParams property to specify which query parameters the controller should accept. Then, we can access the params using the get method on this within the controller's actions.