Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.22 KB

alias-model-in-controller.md

File metadata and controls

48 lines (34 loc) · 1.22 KB

alias-model-in-controller

It makes code more readable if the model has the same name as a subject.

Examples

We can do this in two ways:

  • Alias the model to another property name in the Controller:

    import Controller from '@ember/controller';
    import { alias } from '@ember/object/computed';
    
    export default Controller.extend({
      nail: alias('model')
    });
  • Set it as a property in the Route's setupController method:

    import Route from '@ember/routing/route';
    
    export default Route.extend({
      setupController(controller, model) {
        controller.set('nail', model);
      }
    });

If you're passing multiple models as an RSVP.hash, you can also alias nested properties:

import Controller from '@ember/controller';
import { reads } from '@ember/object/computed';

export default Controller.extend({
  people: reads('model.people'),
  pets: reads('model.pets')
});

Help Wanted

Issue Link
❌ Missing native JavaScript class support #560