Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJs using inject.controller to access parent data

Tags:

ember.js

I am trying to access from a child template to its parent data in the previous versions of emberjs this could have be done using the needs keyword:

app.RepositoriesController = Ember.Controller.extend({
    needs: "user",
    user : Ember.computed.alias("controllers.user");
 });

from what I understand with the new ember version this should be done like the following (as the needs keywords became deprecated):

app.RepositoriesController = Ember.Controller.extend({
    user: Ember.inject.controller('user')
});

but it doesn't seems to work in my html code I use the following line which is blank:

{{user.name}}

Thanks!

like image 601
Nadav Avatar asked Apr 14 '26 11:04

Nadav


1 Answers

All you need to do is call:

user: Ember.inject.controller()

And ember is smart enough to automatically pick up the correct controller based on the property key.

http://emberjs.com/api/classes/Ember.inject.html#method_controller

like image 146
Twig Avatar answered Apr 19 '26 14:04

Twig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!