dimanche 30 juillet 2017

Setting the title of the page using the model from the route

I’m a bit puzzled about setting the title element from my router using the ember-cli-document-title add-on. It works just fine if I pass it a function or a string, but I’m trying to access the current model via modelFor.

It works when the page first loads, but then, when I transition to another route, it changes to ‘undefined’. If I go to a previously visited route the value is populated. It appears that at the time of display, the value is not yet populated. How can I wait for DS to have the attributes on my model instance before trying to assign it to the title?

I had attempted calling reload() on my model, and then returning the resulting promise instead, ember-cli-document-title doesn't seem to like promises in the title attribute.

export default Ember.Route.extend({
  title: function() {
    let model = this.modelFor(this.routeName)
    let title = model.get('title')
    return `${title} | Some More Text`
  }
}




Aucun commentaire:

Enregistrer un commentaire