Why do some controllers have `actions` property while some doesn't?

I am going through the Ember guide currently.

In CREATING A NEW MODEL INSTANCE, the TodosController has actions property and createTodo belongs to actions

On the other hand, in MARKING A MODEL AS COMPLETE OR INCOMPLETE, the TodoController just has isCompleted property without actions property.

Why does one controller use actions property, while another doesn’t?

Thank you.

Actions to Ember controllers are Events to the DOM. If you ever worked with jQuery, you know that you would add click events to specific elements and not to others, depending on whether you want the user to click on that element or not.

The 2 examples that you gave, have 2 different controllers. TodosController is responsible for a group of Todo items, where TodoController is responsible for each individual item. ( another way of saying this, TodosController is the context for the template that represents multiple todos, where TodoController is context for an individual todo )

You can see this visually with the Ember Inspector.

In this example, TodosController is (made) responsible for saving new items, so that’s why it has an action. You could also do the same thing in the route.

You can learn more about Actions in this video: - YouTube

2 Likes