Action Performed in any case! (without event from the templates)


#1

Hi Everyone!

I’m wondering if I can perform an action of the controller from my template, without a button or without any triggering event. I just want that when i pass to this page with the method transitionToRoute() this action will be performed! What i need to do?

Thank you


#2

my suggestion is to not set it as an action. you can have it as an internal method of your route, and call it it from afterModel() (or whatever route lifecycle event you think is appropriate).

export default Route.extend({
  // ...

  afterModel(model, transition) {
    this.hello();
  },

  hello() {
    console.log('hello');
  }
});