Notice - Ember Generated vs Hand-made Controllers

published on March 21, 2013 in technical

Today I found another good thing I did not know about. Which actually feels obvious now, but it did not before I experienced it.

When you let Ember generate controllers for you, things work really well, code is really simple.

Today I had to pass a click context to a method, so I built the view for it, then I needed a place where to put the code which handles the things. This is why I created a controller.

Then a strange thing happened. I got an error telling me that the model, which was passed to the serialize method and previously worked well, is undefined.

I didn't really understand what happened, then it hit me. Ember somehow did not know how to link the hand-made controller to the model.

So I just did this: controller.set("content", model); in the setupController hook. Things just came back to normal.

The conslusion is that when you use a hand-made controller, use a setupController hook too.