Skip to content

Instantly share code, notes, and snippets.

@mehulkar
Created May 29, 2020 02:32
Show Gist options
  • Save mehulkar/1874384e0f618db42ca88b580eda057f to your computer and use it in GitHub Desktop.
Save mehulkar/1874384e0f618db42ca88b580eda057f to your computer and use it in GitHub Desktop.
class ApplicationRoute extends Route {
myAction() {
// do some fancy stuff here
}
setupController(controller, model) {
super.setupController(controller, model);
// Instead of setting on the controller, you can also inject
// a service into this route and set the action there.
controller.set('someProperty', this.myAction);
}
}
// then in application.hbs
// <MyComponent @arg1={{this.someProperty}} />
@hotsoft-desenv2
Copy link

Just for link an official doc with the use of setupController:
https://guides.emberjs.com/release/routing/asynchronous-routing/

// app/routes/tardy.js

import Route from '@ember/routing/route';
import { later } from '@ember/runloop';

export default class TardyRoute extends Route {
  model() {
    return new Promise(function(resolve) {
      later(function() {
        resolve({ msg: 'Hold Your Horses' });
      }, 3000);
    });
  }

  setupController(controller, model) {
    console.log(model.msg); // "Hold Your Horses"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment