How to get `model` property in `route` path?

503 Views Asked by At

How can I get the current route model within current routes action method? I am keep getting error. any one help me here?

my route:

import Ember from 'ember';

export default Ember.Route.extend({
  model: function(params) {

    if(this.store.hasRecordForId('card-list', params.id)){
        return Ember.RSVP.hash({
            model: this.store.peekRecord('card-list', params.id )
        })
    }
  },
  actions:{
    formValidateBeforeNext:function(){
        this.modelFor(this.routeName).get("id");//not works
        console.log(this.controller.get('model').get("id"));//not works
        console.log(this.get('model').get("id"))//not works
        return;
        // this.transitionTo('cs2i.balance.balanceReview');
    }
  }
});

getting error as : TypeError: Cannot read property 'get' of null

3

There are 3 best solutions below

1
GUL On

To get the model within a route action, you can use

this.controller.get("model.id")
0
user2024080 On

finally I tried like: this.controllerFor(this.routeName).get('model') -it works for me. Very thanks to all!!

0
iOS dev On

You can use this.currentModel to access the model in the action methods.