Reputation: 3164
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
Upvotes: 0
Views: 1507
Reputation: 2861
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();
}
});
Upvotes: 2