SuperMarco
SuperMarco

Reputation: 721

Emberjs access controller value from a view

There is a little something that bug me, I don't understand how this cannot works.

I have a lambda controller like this :

App.LambdaController = Ember.ObjectController.extend({
    myVar: null,

    [...]
    // Some function here and here
    [...]
});

And I have a view like that :

var MyRandomView = Em.View.extend({
    actions: {
        myAction : function(data) {
            this.set('controller.enquiry.myVar', data.something);
        }
    }
});

And after that I tried to display this data with a bind-attr helper but its doesn't work.

<img {{bind-attr src=App.LambdaController.myVar}}>

I mean I don't get anything inside my src in the img tag.

Am I doing this wrong ?

http://jsfiddle.net/NQKvy/841/

Upvotes: 0

Views: 87

Answers (1)

JJJ
JJJ

Reputation: 2899

If the lambdaController is the controller thats in scope, do this:

<img {{bind-attr src=myVar}}>

If controller is needed and used by controller in scope, do this:

<img {{bind-attr src=controllers.lambdaController.myVar}}>

Upvotes: 1

Related Questions