Ember.js .setProperties

Quang Nguyen
Sep 3, 2018 · 1 min read

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.

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Quang Nguyen

Written by

Software Engineer

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade