I have a service that handles user authentication and gets the user data via a model. One of the pieces of data that it fetches is a date for the start of a dietary program. I want to use this date to calculate a number: the number of days since the start of the program, so I can use that number to query a different model that pulls content from a CMS.
I haven't been able to access that number anywhere other than a template.
This is the Controller for Dashboard
import Ember from 'ember';
export default Ember.Controller.extend({
authManager: Ember.inject.service('session'),
});
This is the template
You are on a cleanse that starts
You are not on a cleanse.
All of the above code works, but when I try something like this in the controller:
activeCleanse: Ember.computed( function(){
return this.get('authManager.currentUser').then( (user) => {
return user.cleanse_active;
}.bind(this))
}),
startDate: Ember.computed( function(){
return this.get('authManager.currentUser').then( (user) => {
return user.cleanse_start;
}.bind(this))
})
And replace the template with:
You are on a cleanse that starts
You are not on a cleanse.
It doesn't respond to activeCleanse
being false (the template only seems to be checking for its existence) and the date tag only shows [object Object]
.
I am actually trying to get the date in the controller so I can manipulate it to pass as one of the parameters to the dashboard route, which gets a model based on the specific day:
The Dashboard Route
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').queryRecord('cleanse-post', {
filter: {
tag: 'day-1'
}
});
},
});
I want to be able to dynamically set the tag for the filter based on the calculation for the date.
Any help would be appreciated. I feel like I've been going in circles with this and I have no idea what to try.
Aucun commentaire:
Enregistrer un commentaire