0

Is there any way to call route action from another router/controller? Let's say I have two routes:

App.RouteOne = Ember.Object.extend({
   actions: {
      someCommonFunctionality: function() {
         // ...
      }
   }
});

App.RouteTwo = Ember.Object.extend({
   actions: {
      // Here I want to call someCommonFunctionality function from RouteOne
   }
});

Is this somehow possible? I have an AJAX get method that I do not want to repeat in RouteTwo as I have it already in RouteOne

halfer
  • 19,824
  • 17
  • 99
  • 186
Maksim Luzik
  • 5,863
  • 4
  • 36
  • 57
  • Move the AJAX method into a separate service, lets say AJAX service and inject that service into both routes. – Martin Malinda Nov 18 '15 at 10:59
  • Yup. wouldn't be very smart to make common logics into a route and then use it elsewhere. – kristjan reinhold Nov 18 '15 at 11:01
  • Thanks, will do that. But is it so that technically it is not possible to call another router action from router? – Maksim Luzik Nov 18 '15 at 11:03
  • @MaksimLuzik Nope but it's semantically in-correct. – kristjan reinhold Nov 18 '15 at 11:05
  • This is how we use common functions .. import { AccessRights, create_access_rights } from 'xx/utils/access'; import { loaded, load_path, wrap_as_promise } from 'xx/misc/abstract'; – kristjan reinhold Nov 18 '15 at 11:07
  • As Martin Malinda said, Ember.Service is right way to do it. In Addition Ember Actions bubble up route by default if it isnt handled in the current route. So, an action in application route can be accessed from any other route. – acid_srvnn Nov 18 '15 at 11:48

0 Answers0