Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember: Get route instance from the controller

Tags:

ember.js

I have a multi-step flow that the user can go through sequentially or jump straight to a section (if the sections in between are completed). I think this logic should be in the Route object. However, from within the controller, how do I access the route instance. For example, it would be ideal to be able to do something like this in the controller:

App.Flow = Em.ObjectController.extend({   submit: function(){     // Validation and XHR requests     // ...      // Go to the next step     route.goToNextStep();   } } 
like image 530
Jeremy Gillick Avatar asked Jul 03 '13 22:07

Jeremy Gillick


1 Answers

From within a controller, you can access the router via this.get('target'). So this.get('target').send('goToNextStep') should work.

Like so:

App.Flow = Em.ObjectController.extend({   submit: function(){     // ...     this.get('target').send('gotoNextStep');   } }  App.FlowRoute = Ember.Route.extend({   events: {     gotoNextStep: function(){       // ...       this.transitionTo(routeName);     }   } } 
like image 172
Mike Grassotti Avatar answered Sep 30 '22 09:09

Mike Grassotti