Pergunta

Is there a tried and tested way to clear a controller/views properties when leaving a route in Ember JS.

For example, I want to clear all the form fields so if a user revisits this route they are empty.

Cheers

Chris

Foi útil?

Solução

You could clear your controller properties in the route deactivate hook: is executed when the router completely exits this route.

App.FormController = Em.Controller.extend({

  clearForm: function() {
     this.setProperties({
       name: null,
       age: 0,
       ....
     });
  }

});


App.FormRoute = Em.Route.extend({
  deactivate: function() {
    this.controller.clearForm();
  }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top