In Ember.js, events that aren't handled in the controller propagate up the router chain to the application route (see http://emberjs.com/guides/views/handling-events/ for more details).
Is there a way to define an event handler in the controller that allows the event to continue propagating to the router?
App.SampleController = Ember.ObjectController.extend({
myEvent: function(obj) {
this.set('aVariable', true);
}
});
App.ApplicationRoute = Ember.Route.extend({
events: {
myEvent: function(obj) {
this.transitionTo('something');
}
}
});
Is there a way for the myEvent handler in CarsController to set its internal state variable but also kick the event up the chain to the application route? I'm aware of this:
App.__container__.lookup('router:main').send('myEvent', obj);
but it uses Ember internals. I was hoping there was a more standard way to do this.
In Ember. js, controllers allow you to decorate your models with display logic. In general, your models will have properties that are saved to the server, while controllers will have properties that your app does not need to save to the server.
Ember uses templates to organize the layout of HTML in an application. Ember templates use the syntax of Handlebars templates. Anything that is valid Handlebars syntax is valid Ember syntax. Here, {{name}} is a property provided by the template's context.
Ember is a client side framework, primarily used to write Single Page Applications for the Web platform.
One way to achieve this could be:
App.SampleController = Ember.ObjectController.extend({
needs: 'application',
myEvent: function(obj) {
this.set('aVariable', true);
this.get('controllers.application').send('myEvent');
}
});
Working demo.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With