How to get all the properties from ember.js controller?

by mallory_cormier , in category: Javascript , 3 months ago

How to get all the properties from ember.js controller?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 3 months ago

@mallory_cormier 

To get all the properties from an Ember.js controller, you can use the getProperties method provided by Ember. Here's an example of how you can do this:

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

export default Controller.extend({
  someProperty: 'Value 1',
  anotherProperty: 'Value 2',

  init() {
    this._super(...arguments);
    
    // Get all properties as an object
    let allProperties = this.getProperties('someProperty', 'anotherProperty');
    
    // Log the properties
    console.log(allProperties);
  }
});


In this example, we have defined two properties (someProperty and anotherProperty) in the controller. Inside the init function, we use the getProperties method to retrieve these properties as an object and then log them to the console. You can pass multiple property names as arguments to getProperties method to retrieve them all at once.