Ismailp
Ismailp

Reputation: 2383

[EmberJS]: Get selected model in child template

I'm pretty new to Ember and would like to get a selected models value in child controller/template.

I have a sidebar that lists Workspaces. Whenever someone click on workspace the application routes to workspaces/:slugand shows a list of tasks connected to that specific workspace.

I would like to show the selected workspace name in the child route. How would I go about doing that?

My router looks like so:

App.Router.map(function() {
    this.route('login');
    this.resource('workspaces', function() {
      this.route('tasks', {path: ':slug'});
    }); 
});

Been reading a lot of stuff online but haven't quite figured it out.

Thanks.

Upvotes: 2

Views: 69

Answers (1)

Kalman
Kalman

Reputation: 8121

:slug is your dynamic segment. You can access your dynamic segment inside your model hook like so:

App.WorkspacesTasksRoute = Ember.Route.extend({
  model: function(param) {
    return { name: param.slug };
  }
});

See a working jsbin example here

Upvotes: 1

Related Questions