Skip to content

Instantly share code, notes, and snippets.

@praxxis
Last active August 29, 2015 13:58
Show Gist options
  • Save praxxis/10213697 to your computer and use it in GitHub Desktop.
Save praxxis/10213697 to your computer and use it in GitHub Desktop.
Observing parent controller model changes to reset content
App.CommentsNewController = Em.ObjectController.extend({
// create an empty comment when this controller is first created, and when its parent controller changes its model
createNewComment: function () {
this.set('model', DS.Comment.create()); // I don't use Ember Data so this might not be correct
}.on('init').observes('parentController.model'), // `parentController` is a relationship set up by `render`
actions: {
save: function () {
var comment = this.get('model');
comment.save();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment