Change template dynamically from view-model (Aurelia)

Viewed 1611

Is it possible to change which html-template is being used dynamically from the view-model?

E.g. based on data downloaded from a server, I'd like to choose different templates (or some other logic in the view-model)

Update Based on the answer below suggesting getViewStrategy, here's a complete sample:

export class MultiView {
  gender : string

  getViewStrategy() {
      if(this.gender == 'boy')
          return './multi-view-blue.html'
      else
          return './multi-view-pink.html'
  }

  // when view is made visible (e.g. by using the router)
  activate() { 
      this.gender = Math.random()>0.5 ? "boy" : "girl"
  }
}
3 Answers
Related