I'm using ember-cli for an emberjs project. I want a property on my controller to be an alias for a property on my route. I can't find the right way to set it up, and the property is always undefined.
Here's my router:
Router.map(function() {
this.resource('surveys', function() {
this.route('editCompletedSurvey', { path: '/:survey_id/:completed_survey_id' });
});
});
And routes/surveys/edit-completed-survey.js
:
import NewCompletedSurvey from 'myapp/routes/surveys/new-completed-survey';
export default NewCompletedSurvey.extend({
completedSurveyId: null,
model: function(params) {
this.set('completedSurveyId', params.completed_survey_id);
console.log('Set completedSurveyId to ' + params.completed_survey_id); // gets set correctly
return this.store.find('survey', params.survey_id);
}
});
And finally my controller:
export default Ember.ObjectController.extend({
completedSurveyId: Ember.computed.alias('SurveysEditCompletedSurveyRoute.completedSurveyId'), // always 'undefined'. What should this be?
...
Can anyone tell me what the value of the string passed to alias
should be?
The reason I'm doing this is that in my controller I need to access the value of the :completed_survey_id
parameter. I can't use setupController
because that is only called once when the route is first accessed, and I need the controller to be able to access this parameter's value as the user selects different surveys to view. If there's a better way to do that, please tell me (note: completed_survey_id
isn't the ID of a survey
model instance, but is an ID of a different model).