Bunlong
Bunlong

Reputation: 662

How to pass parameter with action using Ember.Button?

In the Ember.js app that I'm working on, I want to pass the parameter from template to controller function but can not.

Template

{{#view Ember.Button target="MyApp.Controller" action="start"}}

{{/view}}

Controller

App.MyAppClass = Ember.Controller.extend({
    actions: {
        start: function(arg) {
            console.log(arg);
        }
    }
});

Are there anyone used to meet this problem?

Upvotes: 2

Views: 2775

Answers (1)

A23
A23

Reputation: 1606

Are you certain that you are referencing the right controller?

I just did a quick mock test with -

/** templates/foobar.hbs **/
<button {{action "foo" "bar"}}>Foobar</button>

/** controllers/foobar.js **/
var FoobarController = Ember.Controller.extend({
    actions: {
       foo: function (args) {
           alert(args); // getting an alert with "bar"
       },
    }
});

I suggest reading - http://emberjs.com/guides/components/sending-actions-from-components-to-your-application/

{{#view Ember.Button target="MyApp.Controller" action="start" param="parameter"}}

{{/view}}

Upvotes: 2

Related Questions