[Resolved] Getting access to the route's model in a Controller upon init


#1

So here’s my scenario:

  • I load the route, and generate a model.
  • I need to check that model to see if it has certain properties, if it does I need to: – Request more information.

However, during the init function of the controller, I do this.get('model') and it always returns null.

Is there an event im supposed to listen to after the model’s been set on the controller? I’m not finding anything anywhere :confused:

import Ember from 'ember';
import { task } from 'ember-concurrency';

export default Ember.Controller.extend({
  actions: {
    setSort(type) {
      this.set('model.sortBy', [type, 'rank:asc']);
    }
  },
  
  init: function(...args) {
    this._super.apply(this, args);

    console.log(this.model); // This is NULL
    console.log(this.get('model')); // This is NULL
    console.log(this.get('currentModel')); // This is UNDEFINED
  },
  
  requestDataTask: task(function* () {
    yield console.log('dostuff here');
  }).maxConcurrency(3)
});

#2

You can observe model, but a better idea is to use the setupController hook in the route.


#3

Just looked up setupController it’s awesome!! TY!!!