Search code examples
ember.js

Unset property on objectcontroller


I have the following router:

Router.map(function() {
    this.resource('cart', function() {
        // order routes
        this.route('shipping');
        this.route('checkout');
        this.route('payment'); 
        this.route('thanks');

    });
});

When I am at the thanks route I want to unset a custom comment property in checkout. This is because the next time the customer visit checkout route the comment is displayed again.

So in thanks, I do the following: this.set('controllers.cart.checkout.commentCustomer', "");

But I get this error: Uncaught Error: Property set failed: object in path "controllers.cart.checkout" could not be found or was destroyed.

What does that means?


Solution

  • You are in luck, because since 1.7.0 Ember has the absolutely wonderful resetController hook in routes. It's exactly for this type of situation.

    App.CartCheckoutRoute = Ember.Route.extend({
        resetController: function(controller, isExiting, transition) {
            controller.set('commentCustomer', '');
        }
    });