Ember.js .setProperties

Quang Nguyen
quangtn0018
Published in
1 min readSep 3, 2018

This is a simple example of when you should use the .setProperties on an Ember object such as the controller.

// search.js
export default Ember.Route.extend({
setupController(controller, model) {
this._super(controller, model)

let foods = ["burger", "sandwiches", "pasta"]
let searchTerm = ""
let searchResults = []
controller.setProperties({
foods,
searchTerm,
searchResults
})
}
})

You would want to do all your logic for the properties that you will be setting to the controller, then using .setProperties , you can set them all at once. I know that when I started using Ember, I set the properties one by one using controller.set(‘propertyName’, propertyValue) which can have a weird flow where as setting all your properties in one place makes more sense.

--

--